题目链接:subsets-ii
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Set;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public class SubsetsII {
-
-
-
-
-
-
-
-
- public Set<List<Integer>> subsets = new HashSet<List<Integer>>();
- public List<List<Integer>> subsetsWithDup(int[] num) {
- Arrays.sort(num);
- subsets(num, 0, new ArrayList<Integer>());
- return new ArrayList<List<Integer>>(subsets);
- }
- public void subsets(int[] S, int step, List<Integer> subset) {
- if(step == S.length) {
- subsets.add(subset);
- return;
- }
-
- subsets(S, step + 1, new ArrayList<Integer>(subset));
-
-
- subset.add(S[step]);
- subsets(S, step + 1, new ArrayList<Integer>(subset));
- }
-
- public static void main(String[] args) {
-
-
- }
-
- }
|