Subsets

Given an integer array nums of distinct elements, return all possible subsets (the power set). Pattern focus: Bitmask Enumeration. Each subset corresponds to one bitmask from 0 to 2^n - 1.

Input Format

nums = distinct integers

Output Format

all subsets of nums

Constraints

  • 1 <= input size <= 10^5
  • -10^9 <= numeric values <= 10^9
  • nums must satisfy the format described in inputFormat.

Examples

Example 1:

Input:

nums = [1,2,3]

Output:

[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]

Explanation:

Every bitmask from 000 to 111 maps to one subset.

Example 2:

Input:

nums = [0]

Output:

[[],[0]]

Explanation:

There are two subsets: empty set and the single-element set.

Loading...
Subsets - Bit Manipulation DSA Problem