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

90. Subsets II

时间:2018-05-20 10:46:10      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:span   problem   res   cto   tar   desc   subsets   tco   star   

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

标签:span   problem   res   cto   tar   desc   subsets   tco   star   

原文地址:https://www.cnblogs.com/JTechRoad/p/9062410.html

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