| 8 | |
| 9 | |
| 10 | class Solution { |
| 11 | public List<List<Integer>> subsetsWithDup(int[] nums) { |
| 12 | List<List<Integer>> result = new ArrayList<>(); |
| 13 | Arrays.sort(nums); // Sort the array to handle duplicates |
| 14 | backtrack(result, new ArrayList<>(), nums, 0); |
| 15 | return result; |
| 16 | } |
| 17 | |
| 18 | private void backtrack(List<List<Integer>> result, List<Integer> current, int[] nums, int start) { |
| 19 | result.add(new ArrayList<>(current)); |
| 20 | |
| 21 | for (int i = start; i < nums.length; i++) { |
| 22 | // Skip duplicates |
| 23 | if (i > start && nums[i] == nums[i - 1]) { |
| 24 | continue; |
| 25 | } |
| 26 | current.add(nums[i]); |
| 27 | backtrack(result, current, nums, i + 1); |
| 28 | current.remove(current.size() - 1); |
| 29 | } |
| 30 | } |
| 31 | } |
nothing calls this directly
no outgoing calls
no test coverage detected