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

来源:互联网 发布:在线卡密域名授权系统 编辑:程序博客网 时间:2024/06/05 19:53

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;    }


0 0
原创粉丝点击