Why it works
- After sorting, equal numbers stand side by side, so a repeat is easy to see: it equals the number just before it.
- Within one call, a branch that starts with a repeat would build the same subsets as the branch of the first copy, so i > start with nums[i] == nums[i - 1] is skipped.
- At i == start the number follows the one just taken, not a sibling branch, so a second 3 after the first one is new: that is how [3, 3] and [1, 3, 3] appear exactly once.
Complexity
Time O(n × 2ⁿ): sorting is O(n log n), then at most 2ⁿ calls, each copying a path of up to n numbers. Memory O(n) besides the answer: the path and the call stack are at most n deep.
nextNow solve it yourself, no hints.
Solve on LeetCode ↗