Loading...
Given an array nums of distinct integers, return every subset of nums (its power set), including the empty subset and nums itself.
To make the answer unique, return the subsets in the following canonical order:
nums in ascending order; call the sorted values s0<s1<⋯<sn−1.Under this rule the empty subset comes first and the full sorted array comes last.
Input: nums = [1,2,3]
Output: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
Explanation: With s = [1,2,3], subset m is chosen by the set bits of m: m=0 -> [], m=1 -> [1], m=2 -> [2], m=3 -> [1,2], m=4 -> [3], m=5 -> [1,3], m=6 -> [2,3], m=7 -> [1,2,3].
Input: nums = [0]
Output: [[],[0]]
Explanation: The only subsets are the empty subset and {0}.
nums.length ≤10nums[i] ≤10nums are unique.Click "Run" to test with sample cases or "Submit" to run all tests.