class Solution {
public:
vector<string> Permutation(string str) {
vector<string> v;
if(str.size() == 0)return v;
Per(v,str,0);
sort(v.begin(),v.end());
return v;
}
void Per(vector<string> &v,string s,int begin){
if(begin == s.size()){
v.push_back(s);
return;
}
for(int i = begin ; i < s.size() ;++i)
{
//if(i != begin && s[i] == s[begin])
//ontinue;
if(check(s,begin,i))
{
swap(s[begin], s[i]);
Per(v,s,begin + 1);
swap(s[begin], s[i]);
}
}
}
bool check(string s,int begin , int j)
{
for(int i = begin ; i < j ;++i)
{
if(s[i] == s[j])
return false;
}
return true;
}
};
剑指offer----字符串的排列
最新推荐文章于 2023-08-19 21:44:17 发布