-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.java
More file actions
32 lines (29 loc) · 894 Bytes
/
Solution.java
File metadata and controls
32 lines (29 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package $090;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author Junlan Shuai[shuaijunlan@gmail.com].
* @date Created on 2:55 PM 2018/07/02.
*/
public class Solution {
public List<List<Integer>> subsetsWithDup(int[] nums) {
List<List<Integer>> lists = new ArrayList<>();
if (nums == null || nums.length == 0){
return lists;
}
Arrays.sort(nums);
subsets(lists, new ArrayList<>(), 0, nums);
return lists;
}
public void subsets(List<List<Integer>> lists, List<Integer> list, int index, int[] nums){
if (!lists.contains(list)){
lists.add(new ArrayList<>(list));
}
for (int i = index; i < nums.length; i++){
list.add(nums[i]);
subsets(lists, list, i + 1, nums);
list.remove(list.size() - 1);
}
}
}