Given an array, find all subsets in the array
Intuition
Use DFS to iterate over all subsets and record them.
Approach
A subset can be represented as a binary number of n digits. Each digit is either 0 or 1. We can use DFS to iterate over all possible such format of binary numbers.
Complexity
Time complexity: iterate all binary numbers of length
$$O(2^n)$$nonce.Space complexity:
$$O(2^n)$$
Code
| |