LeetCode Permutations II

Permutations II

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].

为了代码简洁,就这样吧。其实这个题应该是让自己写一个next_permutation的,但是前面已经写了,在这里就不重复了。
next_permutation的返回值的含义是什么?千万不要想当然了,查查。

class Solution {
public:
    vector<vector<int> > permuteUnique(vector<int> &num) {
		vector<vector<int> > ret;
		sort(num.begin(), num.end());
		ret.push_back(num);
		while(next_permutation(num.begin(), num.end()))
		{
			ret.push_back(num);
		}
		return ret;
    }
};




你可能感兴趣的:(Class,permutation,Numbers,Duplicates)