rocksc30 / LeetCode

用于力扣刷题打卡
2 stars 0 forks source link

90. 子集 II #92

Open rocksc30 opened 1 year ago

rocksc30 commented 1 year ago
class Solution {
    private List<List<Integer>> ans = new ArrayList<>();
    private Deque<Integer> path = new LinkedList<>();
    public List<List<Integer>> subsetsWithDup(int[] nums) {
        Arrays.sort(nums);
        ans.add(new ArrayList<>());
        helper(nums, 0);
        return ans;
    }
    private void helper(int[] nums, int idex){
        if (idex == nums.length) return;
        for (int i = idex; i < nums.length; i++){
            path.add(nums[i]);
            if (!ans.contains(new ArrayList<>(path)))
                ans.add(new ArrayList<>(path));
            helper(nums, i + 1);
            path.removeLast();
        }
    }
}