Subsets

Medium

Given an array nums of distinct integers, return every possible subset (the power set) in any order.

Example 1

subsets()
Input
nums = [1,2,3]
Output
[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]

Example 2

subsets()
Input
nums = [0]
Output
[[],[0]]
Constraints
1 <= nums.length <= 10
All integers in `nums` are unique.

Topics

BacktrackingBit ManipulationArrays

Implement subsets in the editor and return the answer — printing it is never graded.