Problems:
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]
, and [2,1,1]
. 解法一:STL中的next_permutation
class Solution {public: vector> permuteUnique(vector & nums) { vector > result; sort(nums.begin(),nums.end()); do{ result.push_back(nums); }while(next_permutation(nums.begin(),nums.end())); return result; }};