# LeetCode 90 Subsets II

Given a collection of integers that might contain duplicates, nums, 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 nums = [1,2,2], a solution is:

[
[2],
[1],
[1,2,2],
[2,2],
[1,2],
[]
]


	public List<List<Integer>> subsetsWithDup3(int[] nums) {
List<List<Integer>> result = new ArrayList<List<Integer>>();
List<Integer> subSets = new ArrayList<Integer>();
Arrays.sort(nums);
int len = 0, start;
for (int i = 0; i < nums.length; i++) {
/**nums[i-1]已经和前面的子集并在一起作为subSets了,nums[i]==nums[i-1]就不要再做同样的事情了*/
if (i != 0 && nums[i] != nums[i - 1]) start = 0;
else start = len;
len = result.size();
for (int j = start; j < len; j++) {
List<Integer> temp = new ArrayList<>(result.get(j));
}
}
return result;
}


	public List<List<Integer>> subsetsWithDup(int[] nums) {
List<List<Integer>> result = new ArrayList<>();
Arrays.sort(nums);
getSubsetsWithDup(result, new ArrayList<Integer>(), nums, 0);
return result;
}

private void getSubsetsWithDup(List<List<Integer>> result, List<Integer> list, int[] nums, int start) {
for (int i = start; i < nums.length; i++) {
if (i > start && nums[i] == nums[i - 1]) continue;
getSubsets(result, list, nums, i + 1);
list.remove(list.size() - 1);
}
}

#### [LeetCode 90] Subsets II

2015-03-28 00:32:07

#### 90. Subsets II Leetcode Python

2015-01-15 06:03:55

#### LeetCode90:Subsets II

2015-07-08 11:12:56

#### LeetCode 90 Subsets II--In C++

2016-06-04 16:01:54

#### leetcode解题之 77. Combinations&78. Subsets&90. Subsets II java 版（求所有子集）

2017-04-08 19:36:52

#### leetCode 90.Subsets II（子集II） 解题思路和方法

2015-07-25 09:54:00

#### Leetcode 90. Subsets II 子集2 解题报告

2016-07-05 20:51:34

#### LeetCode 90. Subsets II（子集）

2016-05-23 00:34:52

#### Leetcode 90 Subsets II (打印不重复的子集）

2016-11-01 18:58:14

#### LeetCode Subsets 和 LeetCode Subsets II

2014-04-09 22:02:48