86. Subsets

MediumArrayArray

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

Input: Integer array nums of unique elements.

Output: All subsets sorted lexicographically.

Examples

Example 1
Input: [1,2,3]
Output: [[],[1],[1,2],[1,2,3],[1,3],[2],[2,3],[3]]
Explanation: All 2^3=8 subsets.
Example 2
Input: [0]
Output: [[],[0]]
Explanation: 2^1=2 subsets.
Example 3
Input: [1,2]
Output: [[],[1],[1,2],[2]]
Explanation: 2^2=4 subsets.

Constraints

Asked by

BloombergAmazonMetaMicrosoftGoogleFlipkart
Solve this problem in the editor →