Open rocksc30 opened 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(); } } }