Subsets
Problem statement
Given an integer array nums whose elements are unique, return all of its subsets, including the empty subset.
Within each subset, preserve the elements' original input order. Return the subsets in increasing binary-mask order: bit i indicates whether nums[i] belongs to that subset.
Function
subsets(nums: int[]) → int[][]Examples
Example 1
nums = [1,2,3]return = [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]The eight outputs correspond to masks 000 through 111.
Example 2
nums = [0]return = [[],[0]]A one-element array has the empty subset and the subset containing that element.
Constraints
1 <= nums.length <= 10.-10 <= nums[i] <= 10.- All values in
numsare unique.