noodleProblems/
Subsets
#84

Subsets

AlgorithmmediumArrayBacktrackingBit Manipulation

Given an integer array nums of **unique** elements, return all possible subsets (the power set).

The solution set must not contain duplicate subsets. Subsets — and the elements within each subset — may be returned in **any order**.

Example cases

  • three elements
    in nums = [1,2,3]
    out [[],[1],[2],[3],[1,2],[1,3],[2,3],[1,2,3]]
    All 2^3 = 8 subsets, including the empty set.
  • single
    in nums = [0]
    out [[],[0]]
  • negatives
    in nums = [-1,2]
    out [[],[-1],[2],[-1,2]]

Constraints

  • 1 <= nums.length <= 10
  • -10 <= nums[i] <= 10
  • All numbers are unique.
Saved
nums =
[1,2,3]