题目意思
求一个数组的全排列(会有重复的数字)
题解
class Solution {
public:
void dfs(vector<int> nums, int st, int ed, vector<vector<int>> &res) {
if (st == ed) {
res.push_back(nums);
return ;
}
for(int i=st; i<ed; i++) {
if(i != st && nums[i] == nums[st]) continue;
swap(nums[i], nums[st]);
dfs(nums, st+1, ed, res);
}
return ;
}
vector<vector<int>> permuteUnique(vector<int>& nums) {
sort(nums.begin(), nums.end());
vector<vector<int>> res;
dfs(nums, 0, nums.size(), res);
return res;
}
};