78. Subsets
Given a set of distinct integers, nums, return all possible subsets.
Note:
Elements in a subset must be in non-descending order.
The solution set must not contain duplicate subsets.
For example,
If nums = [1,2,3], a solution is:
[
[],
[3],
[1],
[2],
[1,2,3],
[1,3],
[2,3],
[1,2]
]
@tag-array

Algorithm

For the example [1,2,3] given in the title,

it is an empty set at the beginning,

then we have to deal with 1, add 1 to the empty set, which is [1], and now we have two selves [] And [1],

let’s deal with 2, we add 2 to each of the previous subsets, and we can get [2], [1, 2], then all the subsets are now [], [1], [2], [1, 2],

in the same way, we can get [3], [1, 3], [2, 3], [1, 2, 3], plus all of previous the subsets