Permutations II(leetcode)
Given a collection of numbers that might contain duplicates, return all possible unique permutations.
For example,
[1,1,2]
have the following unique permutations:
[ [1,1,2], [1,2,1], [2,1,1] ]
代码:
class Solution {
public:
vector<vector<int>> permuteUnique(vector<int>& nums) {
vector<int> temp = nums;
vector<vector<int> > solution;
solution.push_back(nums);
next_permutation(nums.begin(), nums.end());
while (temp != nums) {
solution.push_back(nums);
next_permutation(nums.begin(), nums.end());
}
return solution;
}
};