思路:回溯+哈希表
class Solution {
public:
vector<string> res;
unordered_map<string,int> memo;
void getRes(string s,string trace){
if(s.size()==0) {
if(memo.find(trace)==memo.end()){
memo[trace]=1;
res.push_back(trace);
}
return;
}
for(int i=0;i<s.size();i++){
char ch=s[i];
s.erase(s.begin()+i);
trace+=ch;
getRes(s,trace);
trace.pop_back();
s.insert(s.begin()+i,ch);
}
}
vector<string> permutation(string s) {
getRes(s,"");
return res;
}
};