Skip to content

Commit c462986

Browse files
committed
subsets.II
1 parent f6f6a00 commit c462986

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/subsets/subsets.II.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)