Subsets

Easy~20 min

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

The solution set must not contain duplicate subsets. Return the solution in any order.

Examples

Example 1
Input: nums = [1,2,3]
Output: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
Explanation: The power set of [1,2,3] contains 2³ = 8 subsets, from the empty set to the full set.
Example 2
Input: nums = [0]
Output: [[],[0]]
Explanation: A single-element array has exactly 2 subsets: the empty set and the set containing that element.

Constraints

  • 1 <= nums.length <= 10
  • -10 <= nums[i] <= 10
  • All the numbers of nums are unique
  • Expected time complexity: O(2^n)
Code
Ctrl+EnterRun|Ctrl+⇧+EnterSubmit
Output

Run your code to see results

Use Cmd+Enter to run