cheetcode

71. SubsetsMedium

Return every possible subset of a list of distinct numbers.

Given an integer array of unique elements, return all possible subsets.

The runner accepts the subsets in any order.

Build one partial choice at a time, recurse, then undo that choice before exploring the next option. Pay close attention to duplicate handling and stopping conditions.

Examples

Input: nums = [1,2,3]
Output: [[],[1],[2],[3],[1,2],[1,3],[2,3],[1,2,3]]
Input: nums = [0]
Output: [[],[0]]

Constraints

  • 1 <= nums.length <= 10
  • -10 <= nums[i] <= 10
  • All elements are unique.