给定一个可能包含重复整数的列表,返回所有可能的子集(幂集)。
注意事项:解决方案集不能包含重复的子集。
例如,如果 nums = [1,2,2],答案为:
[
  [2],
  [1],
  [1,2,2],
  [2,2],
  [1,2],
  []
]
详见:https://leetcode.com/problems/subsets-ii/description/

Java实现:

class Solution {
public List<List<Integer>> subsetsWithDup(int[] nums) {
List<List<Integer>> res=new ArrayList<List<Integer>>();
List<Integer> out=new ArrayList<Integer>();
Arrays.sort(nums);
helper(nums,0,out,res);
return res;
}
private void helper(int[] nums,int start,List<Integer> out,List<List<Integer>> res){
res.add(new ArrayList<Integer>(out));
for(int i=start;i<nums.length;++i){
out.add(nums[i]);
helper(nums,i+1,out,res);
out.remove(out.size()-1);
while(i+1<nums.length&&nums[i]==nums[i+1]){
++i;
}
}
}
}

参考:https://www.cnblogs.com/grandyang/p/4310964.html

090 Subsets II 子集 II的更多相关文章

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

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

  2. LeetCode 90 | 经典递归问题,求出所有不重复的子集II

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode专题第56篇文章,我们一起来看看LeetCode第90题,子集II(Subsets II). 这题的官方难度是Medi ...

  3. 90. 子集 II

    90. 子集 II 题意 给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: [1,2,2]输出:[ [2], [1], ...

  4. LeetCode:子集 II【90】

    LeetCode:子集 II[90] 题目描述 给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: [1,2,2] 输出: ...

  5. Java实现 LeetCode 90 子集 II(二)

    90. 子集 II 给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: [1,2,2] 输出: [ [2], [1], [ ...

  6. [leetcode] 90. 子集 II.md

    90. 子集 II 78. 子集题的扩展,其中的元素可能会出现重复了 我们仍沿用78题的代码,稍作改动即可: 此时需要对nums先排个序,方便我们后面跳过选取相同的子集. 跳过选取相同的子集.当选取完 ...

  7. 如何使用SignalTap II觀察reg與wire值? (SOC) (Verilog) (Quartus II) (SignalTap II)

    Abstract撰寫Verilog時,雖然每個module都會先用ModelSim或Quartus II自帶的simulator仿真過,但真的將每個module合併時,一些不可預期的『run-time ...

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

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

  9. [LeetCode]题解(python):090 Subsets II

    题目来源 https://leetcode.com/problems/subsets-ii/ Given a collection of integers that might contain dup ...

随机推荐

  1. this.triggerEvent()用法

    在对组件进行封装时 在当前页面想要获取组件中的某一状态,需要使用到this.triggerEvent(' ',{},{}),第一个参数是自定义事件名称,这个名称是在页面调用组件时bind的名称,第二个 ...

  2. haproxy官方配置文档地址

    http://cbonte.github.io/haproxy-dconv/1.6/configuration.html#4-option%20http-keep-alive

  3. 将PHP数组输出为HTML表格

    1. [代码][PHP]代码    <?phpclass xtable{    private $tit,$arr,$fons,$sextra;    public function __con ...

  4. hpuoj 1193: Interval

    Interval [STL.双指针.二分] 题目链接 http://acm.hpu.edu.cn/problem.php?id=1193 或者 题目链接 http://acm.nyist.net/Ju ...

  5. 多线程之:lock和synchronized的区别

    多次思考过这个问题,都没有形成理论,今天有时间了,我把他总结出来,希望对大家有所帮助 1.ReentrantLock 拥有Synchronized相同的并发性和内存语义,此外还多了 锁投票,定时锁等候 ...

  6. AutoIt中ControlFocus的使用

    在使用AutoIt最控件做自动化操作的时候,经常性的会碰到无法使用Windows Info工具获取控件的属性,但是我们又需要获取该控件的焦点,我们该怎么办呢? 方法1: 应用controlFocus方 ...

  7. linux 查看某进程 并杀死进程 ps grep kill

    Linux 中使用top 或 ps 查看进程使用kill杀死进程 1.使用top查看进程: $top 进行执行如上命令即可查看top!但是难点在如何以进程的cpu占用量进行排序呢? cpu占用量排序执 ...

  8. 微信小程序把玩(三十)wx.request(object) API

    这里通过干活集中营的API接口真实请求下数据.如果提示URL 域名不合法,请在 mp 后台配置后重试修改asdebug.js两行代码即可可看下面图 百牛信息技术bainiu.ltd整理发布于博客园 定 ...

  9. swprintf has been changed to conform with the ISO C standard, adding an extra character count parameter.

    'swprintf': swprintf has been changed to conform with the ISO C standard, adding an extra character ...

  10. Visual Studio 2013 Update 1

    Visual Studio 2013 Update 1 VS2013.1.iso 共 245 MB http://download.microsoft.com/download/8/2/6/826E2 ...