Write subsets(nums) that returns every subset of nums as a list of lists.
- The values in
numsare distinct integers;0 <= len(nums) <= 10. - Include the empty subset and the whole list. No subset may appear twice.
- The subsets can come in any order, and the elements inside each subset can be in any order.
subsets([5, 2]) # [[], [5], [2], [5, 2]] in some order
subsets([]) # [[]]
Show hint
each element is either in a subset or not, so there are 2^n subsets. Decide for one index at a time, and undo the choice when you come back.