81. Subsets
Medium · Backtracking
Given an array of distinct integers, return all possible subsets (the power set). The solution set must not contain duplicate subsets.
A subset is a collection of elements from the original array where order does not matter. The empty set is always a valid subset.
Examples
Example 1 Input: [1, 2, 3] Output: [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]] Explanation: There are 2^3 = 8 total subsets. Each element can either be included or excluded from a subset.
Example 2 Input: [0] Output: [[], [0]] Explanation: A single-element array has exactly 2 subsets: the empty set and the set containing that element.
Constraints
- Standard input/output constraints apply