面试题 08.08
Solutions
class Solution {
public:
vector<string> res;
void dfs(string & S, int st) {
if (st == S.size())
res.push_back(S);
else {
vector<int> used(128);
for (int i = st; i < S.size(); i++) {
if (used[S[i]]++) continue;
swap(S[st], S[i]);
dfs(S, st + 1);
swap(S[st], S[i]);
}
}
}
vector<string> permutation(string S) {
dfs(S, 0);
return res;
}
};Last updated