# Middle-题目57：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],
[]
]

Middle-题目52，但这里面的数组会有重复元素，但子集中仍不允许有重复元素。

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

private void backtrack(int[] nums, int index, List<List<Integer>> result, List<Integer> sublist) {
if(index <= nums.length) {
}
for(int i = index; i < nums.length; i++) {
if(i != index && nums[i] == nums[i - 1]) {
continue;
}
backtrack(nums, i + 1, result, sublist);
sublist.remove(sublist.size() - 1);
}
}
}

3ms,beats 41.85%,众数3ms,41.53%
Cmershen的碎碎念：

#### LeetCode90:Subsets II

2015-07-08 11:12:56

#### [LeetCode 90] Subsets II

2015-03-28 00:32:07

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

2016-06-04 16:01:54

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

2015-07-25 09:54:00

#### 90. Subsets II Leetcode Python

2015-01-15 06:03:55

#### Subsets II -- LeetCode

2014-04-28 04:23:53

#### LeetCode Subsets 和 LeetCode Subsets II

2014-04-09 22:02:48

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

2017-04-08 19:36:52

#### LeetCode 90：Subsets II

2016-01-25 17:09:43

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

2016-11-01 18:58:14