题目描述
输入一个字符串,按字典序打印出该字符串中字符的所有排列。例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba。
输入描述:
输入一个字符串,长度不超过9(可能有字符重复),字符只包括大小写字母。
解法:使用STL的next_permutation(a,a+l) !!!注意l为字符串长度,即终止符的下一位位置
class Solution {
public:
vector<string> Permutation(string str) {
char ch[10];
vector<string> s1;
if (str.length()==0)
return s1;
int j=0;
for (int i=0;i<str.length();i++)
{
if(str[i]<='z'&&str[i]>='a')
ch[j++]=str[i];
if(str[i]<='Z'&&str[i]>='A')
ch[j++]=str[i];
}
ch[j]='\0';
do{
s1.push_back(string(ch));
}while(next_permutation(ch,ch+j));
return s1;
}
};
1494

被折叠的 条评论
为什么被折叠?



