码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode:Permutations II

时间:2015-06-12 16:41:11      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:

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<vector<int>> permuteUnique(vector<int>& nums) {
        vector<vector<int>> result;
        
        sort(nums.begin(),nums.end());
        do{
            result.push_back(nums);
        }while(next_permutation(nums.begin(),nums.end()));
        
        return result;
        
    }
};

 

LeetCode:Permutations II

标签:

原文地址:http://www.cnblogs.com/xiaoying1245970347/p/4571721.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!