Subsets
Given an integer array nums of unique elements, return all possible subsets (the power set). The solution set must not contain duplicate subsets, and the subsets may be returned in any order.
Open official problem prompt ↗Produce the power set: every possible selection of elements, from the empty set up to the whole array.
Picture packing for a trip with 3 items on the table. For each item you make one yes/no decision; the set of all decision paths is exactly the set of all possible bags you could pack.
- Input
- nums = [1, 2, 3]
- Output
- [[], [1], [1,2], [1,2,3], [1,3], [2], [2,3], [3]]
- Why
- Every combination of choosing or skipping each of the 3 elements yields 2^3 = 8 distinct subsets.
1 <= nums.length <= 10-10 <= nums[i] <= 10All the numbers of nums are unique