给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集)。

说明:解集不能包含重复的子集。

示例:

输入: [1,2,2] 输出: [ [2], [1], [1,2,2], [2,2], [1,2], [] ]

class Solution {
public:
int len;
vector<vector<int> > res;
vector<vector<int> > subsetsWithDup(vector<int>& nums)
{
sort(nums.begin(), nums.end());
len = nums.size();
vector<int> temp;
DFS(nums, temp, 0);
return res;
} void DFS(vector<int>& nums, vector<int> temp, int pos)
{
res.push_back(temp);
for(int i = pos; i < len; i++)
{
temp.push_back(nums[i]);
DFS(nums, temp, i + 1);
temp.pop_back();
for(; i < len - 1; i++)
{
if(nums[i + 1] != nums[i])
{
break;
}
}
}
}
};

Leetcode90. Subsets II子集2的更多相关文章

  1. LeetCode90:Subsets II

    Given a collection of integers that might contain duplicates, nums, return all possible subsets. Not ...

  2. [LeetCode] Subsets II 子集合之二

    Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: ...

  3. [LeetCode] 90. Subsets II 子集合之二

    Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: ...

  4. 090 Subsets II 子集 II

    给定一个可能包含重复整数的列表,返回所有可能的子集(幂集).注意事项:解决方案集不能包含重复的子集.例如,如果 nums = [1,2,2],答案为:[  [2],  [1],  [1,2,2],  ...

  5. Leetcode之回溯法专题-90. 子集 II(Subsets II)

    Leetcode之回溯法专题-90. 子集 II(Subsets II) 给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入 ...

  6. [leetcode]90. Subsets II数组子集(有重)

    Given a collection of integers that might contain duplicates, nums, return all possible subsets (the ...

  7. 42. Subsets && Subsets II

    Subsets Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset ...

  8. 【leetcode】Subsets II

    Subsets II Given a collection of integers that might contain duplicates, S, return all possible subs ...

  9. 【LeetCode】90. Subsets II (2 solutions)

    Subsets II Given a collection of integers that might contain duplicates, S, return all possible subs ...

随机推荐

  1. 面试系列15 如何保证Redis的高并发和高可用

    就是如果你用redis缓存技术的话,肯定要考虑如何用redis来加多台机器,保证redis是高并发的,还有就是如何让Redis保证自己不是挂掉以后就直接死掉了,redis高可用 我这里会选用我之前讲解 ...

  2. Nvelocity 语法

    原文:Nvelocity 语法 1,数字循环   #foreach($i in [0..9])     $i #end 2,dictionary 根据key获取value值 #set($key1=&q ...

  3. matlab-使用技巧

    sel(1:100); 1 2 3 4 5 ...100 X(sel, :); 1.......2.......3.......4.......5..........100...... nn_para ...

  4. 查看linux的shhd端口号 netstat | grep sshd

    [root@iZ2zef51hufoaycipfxek8Z ~]# [root@iZ2zef51hufoaycipfxek8Z ~]# netstat | grep sshd [root@iZ2zef ...

  5. openSUSE安装Composer

    使用的是LAMP,PHP版本为7.0.7. 在终端中,运行以下命令 php -r "copy('https://install.phpcomposer.com/installer', 'co ...

  6. zabbix自动发现主机(转)

    zabbix自动发现主机 2018年06月15日 18:02:52 loyal-Wang 阅读数:817更多 个人分类: zabbix   版权声明:本文为博主原创文章,转载请注明出处. https: ...

  7. iOS之CAShapeLayer属性简介

    1.CAShapeLayer需要和贝塞尔曲线一块使用! #import <QuartzCore/CALayer.h> NS_ASSUME_NONNULL_BEGIN CA_CLASS_AV ...

  8. Python学习day37-并发编程(3)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  9. python3-常用模块之os

    os模块,os是和操作系统交互的模块 os.getcwd() :获取当前工作目录,即当前python脚本工作的目录路径,如果是命令行模式下,同样表示当前目录下 os.listdir(路径): 列出指定 ...

  10. for update行级锁的作用

    1.for update叫排它锁,是一种行级锁,一旦用户对某个行施加了行级加锁,则该用户可以查询也可以更新被加锁的数据行,其它用户只能查询但不能更新被加锁的数据行.如果其它用户想更新该表中的数据行,则 ...