Power Set of an Array
Implement subsets
You're given an array
nums whose values never repeat. Produce its power set — every subset that can be formed from it, from the empty subset all the way up to the full array itself, with nothing missing and nothing duplicated.
Each element has exactly two states — in the subset, or not — so an array of n elements has exactly 2ⁿ possible subsets. That count is fixed by the problem itself, not by how it's solved: any correct approach visits every one of those 2ⁿ combinations at least once.
Example 1:
Input: nums = [1,2,3]
Output: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
Example 2:
Input: nums = []
Output: [[]]
Example 3:
Input: nums = [0]
Output: [[],[0]]
+ 9 hidden test cases run on Submit.
Constraints:
- ●
0 ≤ nums.length ≤ 10 - ●
-10 ≤ nums[i] ≤ 10 - ●
Every value in nums is distinct
nums =
[1, 2, 3]