public List<List<Integer>> subsetsWithDup(int[] nums) {
List<List<Integer>> list = new ArrayList<>();
list.add(new ArrayList<>());
for(int i = 1; i <= nums.length; i++) {
Set<List<Integer>> tlist = recurSub(nums, 0, i);
for(List<Integer> tmp: tlist) {
list.add(tmp);
}
}
return list;
}
public Set<List<Integer>> recurSub(int[] nums, int start,int len) {
Set<List<Integer>> list = new HashSet<>();
for(int i = start; i < nums.length; i++) {
if(len > 1) {
for(List<Integer> tList : recurSub(nums, i+1, len-1)) {
tList.add(nums[i]);
Collections.sort(tList);
list.add(tList);
}
}else if(len == 1) {
list.add(new LinkedList<Integer>(Arrays.asList(nums[i])));
}
}
return list;
}
90. Subsets II
最新推荐文章于 2025-05-07 11:37:05 发布