作者:越野瘾君子_939 | 来源:互联网 | 2023-06-20 12:37
链接:https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/
代码:
class Solution {
public:
vector<string> permutation(string s) {
vector<string> res;
sort(s.begin(), s.end());
dfs(s, 0, s.size(), res);
return res;
}
void dfs(string s, int l, int r, vector<string>& res) {
if (l == r) res.push_back(s);
else {
for (int i = l; i i) {
if (i > l && s[i] == s[l]) continue;
swap(s[i], s[l]);
dfs(s, l + 1, r, res);
}
}
}
};