class Solution {
public:
void dfs(set<string>&s,string&str,string &temp,vector<bool>&f)
{
bool flag=true;
for(int i=0;i<str.length();i++)
{
if(f[i])continue;
f[i]=true;
flag=false;
temp.push_back(str[i]);
dfs(s,str,temp,f);
f[i]=false;
temp.pop_back();
}
if(flag)s.insert(temp);
}
vector<string> Permutation(string str) {
string temp="";
set<string>s;
vector<string>res;
vector<bool>f(str.length(),false);
dfs(s,str,temp,f);
for(auto x:s)res.push_back(x);
return res;
}
};

京公网安备 11010502036488号