LeetCode 47 Full Permutation II
Given a sequence that can contain repeated numbers, return all non-repeating full permutations.
Example:
enter:
[1,1,2]
Output:
[
[1,1,2],
[1,2,1],
[2,1,1]
]
Just use the next_permutation function directly. Note that there are duplicate elements, so the AC code is as follows:
class Solution {
public:
vector<vector<int>> permuteUnique(vector<int>& nums) {
map<vector<int>,int>m;
vector<vector<int>>ans;
sort(nums.begin(),nums.end());
do{
if(m[nums]==0){
ans.push_back(nums);
}
}while(next_permutation(nums.begin(),nums.begin()+nums.size()));
return ans;
}
};