public class Solution {
public List<List<Integer>> subsetsWithDup(int[] nums) {
List<List<Integer>> res = new LinkedList<>();
if (nums == null || nums.length == 0) {
return res;
}
List<Integer> list = new LinkedList<>();
Arrays.sort(nums);
helper(res, list, nums, 0);
return res;
}
private void helper(List<List<Integer>> res, List<Integer> list, int[] nums, int pos) {
res.add(new LinkedList<>(list));
for (int i = pos; i < nums.length; i++) {
if (i != pos && nums[i] == nums[i - 1]) {
continue;
}
list.add(nums[i]);
helper(res, list, nums, i + 1);
list.remove(list.size() - 1);
}
}
}
Subsets II
最新推荐文章于 2021-07-01 16:49:32 发布