class Solution {
public:
string path;
unordered_set<string>set;//去重
vector<string>ans;
int n;
void f(string s,int dep){
if(dep==n){
set.insert(path);
return;
}
path.push_back(s[dep]);
f(s,dep+1);
path.pop_back();//恢复现场
f(s,dep+1);
}
vector<string> generatePermutation(string s) {
n=s.size();
f(s,0);
for(string path:set){
ans.push_back(path);
}
return ans;
}
};
第1题【算法讲解038【必备】常见经典递归过程解析】 https://www.bilibili.com/video/BV19m4y1n7mo/?share_source=copy_web&vd_source=5065fa61022691e8df35c771a30e6d29

京公网安备 11010502036488号