Subsets with repeated elements
来源:互联网 发布:淘宝内衣店铺简介 编辑:程序博客网 时间:2024/05/17 02:14
Given a collection of integers that might contain duplicates, S, return all possible subsets.
Note:
- Elements in a subset must be in non-descending order.
- The solution set must not contain duplicate subsets.
For example,
If S = [1,2,2]
, a solution is:
[ [2], [1], [1,2,2], [2,2], [1,2], []]public ArrayList<ArrayList<Integer>> subsetsWithDup(int[] num) { // Note: The Solution object is instantiated only once and is reused by each test case. Arrays.sort(num); return help(num, 0); } public ArrayList<ArrayList<Integer>> help(int[] num, int index) { ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>(); Set<ArrayList<Integer>> set = new HashSet<ArrayList<Integer>>(); if(index == num.length) { result.add(new ArrayList<Integer>()); return result; } for(ArrayList<Integer> sub : help(num, index + 1)) { set.add(sub); ArrayList<Integer> a = new ArrayList<Integer>(); a.add(num[index]); a.addAll(sub); if(!set.contains(a)) set.add(a); } result.addAll(set); return result; }
- Subsets with repeated elements
- 【LeetCode with Python】 Subsets
- How do I remove repeated elements from ArrayList?
- 【LeetCode with Python】 Subsets II
- Style page elements with CSS
- Selenium - Working with SELECT elements
- HTML:Getting Intimate with Elements
- P27 (**) Group the elements of a set into disjoint subsets.
- Select m elements from max elements with limits
- Find number of subsets with equal sum
- Sharing a Single Style with Heterogeneous Elements
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- prim和kruscal区别
- All possible paths
- [Leetcode77, medium] Combination
- Linked List Cycle
- Subsets
- Subsets with repeated elements
- [leetcode 78 & 90, Medium] Subsets I and II
- Socket Receive数据一次性接收不全的问题
- 关于socket大数据收发解决方案
- c语言socket 传输 大数据量
- 几个重要的TCP/IP选项解析(Java Socket)
- 使用dropbear搭建ssh服务。
- 自动化测试工具总结
- hdoj4704 Sum ( 费马小定理 )