We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f6f6a00 commit c462986Copy full SHA for c462986
src/subsets/subsets.II.java
@@ -0,0 +1,19 @@
1
+public class Solution {
2
+ public List<List<Integer>> subsetsWithDup(int[] num) {
3
+ Arrays.sort(num);
4
+ List<List<Integer>> results = new ArrayList<List<Integer>>();
5
+ results.add(new LinkedList<Integer>());
6
+ int size = 0;
7
+ int startIndex = 0;
8
+ for (int i=0; i<num.length; i++) {
9
+ startIndex = (i >= 1 && num[i] == num[i-1]) ? size : 0;
10
+ size = results.size();
11
+ for (int j=startIndex; j<size; j++) {
12
+ List<Integer> res = new LinkedList<Integer>(results.get(j));
13
+ res.add(num[i]);
14
+ results.add(res);
15
+ }
16
17
+ return results;
18
19
+}
0 commit comments