Given an array nums of distinct integers, return every subset of nums (its power set), including the empty subset and nums itself. There are exactly 2n of them.
The subsets may be returned in any order. Within a subset, list the elements in the order they appear in nums.
Examples
Example 1
Input: nums = [1,2,3]
Output: [[],[1],[1,2],[1,2,3],[1,3],[2],[2,3],[3]]
Explanation: All 2^3 = 8 subsets. Any order of the subsets is accepted; they are shown here sorted.
Example 2
Input: nums = [0]
Output: [[],[0]]
Explanation: The only subsets are the empty subset and {0}.
Example 3
Input: nums = [3,1]
Output: [[],[1],[3],[3,1]]
Explanation: The full subset is [3,1], not [1,3]: within a subset the elements keep the order they have in nums.
Constraints
1≤nums.length≤10
−10≤nums[i]≤10
All the numbers of nums are unique.
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up