Asked at
Subsets
MediumVerifiedBacktrackingArrayRecursion~20 min
Given an array of distinct integers nums, return all possible subsets (the power set).
The solution set must not contain duplicate subsets. Return them in any order.
The input arrives as a single array nums.
Examples
in[1, 2, 3]
out[[], [1], [1,2], [1,2,3], [1,3], [2], [2,3], [3]]
Every combination of including or excluding each element.
in[0]
out[[], [0]]
Two subsets: empty and the full set.
Constraints
- 1 ≤ nums.length ≤ 10
- -10 ≤ nums[i] ≤ 10
- All numbers are distinct.
Get help
🔑
Sign in to solve
Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.