Subsets II
MediumP2Coding
nums may contain duplicates. Return all distinct subsets (the power set without repeats), in any order. Elements inside a subset may be listed in any order, and two subsets are the same if they hold the same values the same number of times.
Example 1
- Input
- nums = [1,2,2]
- Output
- [[],[1],[1,2],[1,2,2],[2],[2,2]]
- Why
- Six distinct subsets; [2] and [1,2] appear once.
Example 2
- Input
- nums = [0]
- Output
- [[],[0]]
Example 3
- Input
- nums = [1,1,1]
- Output
- [[],[1],[1,1],[1,1,1]]
Constraints
- 1 <= nums.length <= 12
- -10 <= nums[i] <= 10
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.