随意写一个题解,由字符串全排列来的,unordered_set可以取出重复元素
``class Solution {
unordered_set[HTML_REMOVED] result;
public:
void DFS(vector[HTML_REMOVED]& nums, string res){
if (nums.size() == 0){
result.insert(res);
}
for (int i = 0; i < nums.size(); i){
string temp(res);
temp += (nums[i]-‘0’);
vector[HTML_REMOVED] help;
for (int j = 0; j < nums.size(); j){
if (j != i) help.push_back(nums[j]);
}
DFS(help, temp);
}
}
vector[HTML_REMOVED]> permutation(vector[HTML_REMOVED]& nums){
string res=”“;
DFS(nums, res);
vector[HTML_REMOVED]> ret;
for (auto i = result.begin(); i != result.end(); i){
vector[HTML_REMOVED] temp;
for (int j = 0; j < (*i).size(); j){
temp.push_back((*i)[j] + ‘0’);
}
ret.push_back(temp);
}
return ret;
}
};
``