您的位置:首页 > 编程语言 > C语言/C++

Leetcode Problem.47—Permutations II C++实现

2015-06-05 13:09 337 查看
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]
.
全排列,并且去掉重复情况。

我的C++程序!STL算法实现。

vector<vector<int>> permuteUnique(vector<int>& nums) {
        int len=nums.size();
        vector<vector<int>> result;
        vector <int>temp;
        sort(nums.begin(),nums.end());
        do {
             for(int i=0;i<len;i++)
               temp.push_back(nums[i]);
             result.push_back(temp);
             temp.clear();
           } while (next_permutation(nums.begin(),nums.end()));
         return result;
    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: