【LeetCode】 784. 字母大小写全排列

版权声明:made by YYT https://blog.csdn.net/qq_37621506/article/details/83717903

1.题目

给定一个字符串S,通过将字符串S中的每个字母转变大小写,我们可以获得一个新的字符串。返回所有可能得到的字符串集合。

2.思路

递归思路

3.代码

class Solution {
public:
    void change(vector<string> &res,string S,int i){
	int len=S.length();
	if(i>len){
		res.push_back(S);
		return ;
	}
	if(S[i]>='a'&&S[i]<='z'){
		S[i]-= 32;
        change(res,S,i+1);
        S[i] += 32;
	}
	if(S[i]>='A'&&S[i]<='Z'){
		S[i]+= 32;
        change(res,S,i+1);
        S[i]-= 32;
	}
	change(res,S,i+1);
}
    vector<string> letterCasePermutation(string S) {
        vector<string>res;
	change(res,S,0);
	vector<string>::iterator t;
	for(t=res.begin();t!=res.end();t++){
		cout<<*t<<endl;
	}
	return res;
    }
};

猜你喜欢

转载自blog.csdn.net/qq_37621506/article/details/83717903