题目要求: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].

 

代码如下:

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

 

相关文章:

  • 2021-06-27
  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2021-05-29
猜你喜欢
  • 2021-12-24
  • 2021-07-25
  • 2021-05-19
  • 2022-03-06
相关资源
相似解决方案