标签:
输入一个字符串,长度不超过9(可能有字符重复),字符只包括大小写字母。
1 class Solution { 2 public: 3 void Permutation(string str,int begin,int end,vector<string>& result) 4 { 5 if (begin > end) 6 { 7 result.push_back(str); 8 return; 9 } 10 for (int i = begin ; i <= end ; ++i) 11 { 12 if(str[begin] != str[i] || begin == i) 13 { 14 char tem = str[begin]; 15 str[begin] = str[i]; 16 str[i] = tem; 17 Permutation(str,begin+1,end,result); 18 tem = str[begin]; 19 str[begin] = str[i]; 20 str[i] = tem; 21 } 22 } 23 } 24 vector<string> Permutation(string str) { 25 vector<string> reslut; 26 if (str.length() == 0) 27 return reslut; 28 Permutation(str,0,str.length()-1,reslut); 29 std::sort(reslut.begin(),reslut.end()); 30 return reslut; 31 } 32 };
标签:
原文地址:http://www.cnblogs.com/xiaoyesoso/p/5157922.html