90. Subsets II

Posted The Tech Road

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了90. Subsets II相关的知识,希望对你有一定的参考价值。

https://leetcode.com/problems/subsets-ii/description/

class Solution {
public:
    vector<vector<int>> subsetsWithDup(vector<int>& nums) {
        vector<vector<int>> res;
        res.push_back(vector<int>());
        sort(nums.begin(), nums.end());
        for (int j = 0, pre_sz; j < nums.size(); j++) {
            int n = nums[j];
            int sz = res.size();
            int start = (j > 0 && nums[j] == nums[j-1]) ? pre_sz : 0;
            pre_sz = sz;
            for (int i = start; i < sz; i++) {
                vector<int> v = res[i];
                v.push_back(n);
                res.push_back(v);
            }
        }
        return res;
    }
};

 

以上是关于90. Subsets II的主要内容,如果未能解决你的问题,请参考以下文章

90. Subsets II

#Leetcode# 90. Subsets II

90. Subsets II

[LeetCode] 90. Subsets II 子集合 II

LeetCode 90:Subsets II

Leetcode 90. Subsets II