Skip to content
BASA DSA

Subsets

MediumBacktracking

Return all subsets of a list of distinct integers, including the empty subset. Each subset and the result may be ordered arbitrarily.

Example 1

Input
nums = [2,5]
Output
[[],[2],[5],[2,5]]

Explanation

Each of 2 and 5 may be included or excluded, giving four subsets.

Example 2

Input
nums = []
Output
[[]]

Explanation

Empty input has exactly one subset: the empty subset.

Example 3

Input
nums = [9]
Output
[[],[9]]

Explanation

A singleton has the empty subset and the subset containing 9.

Constraints

  • 0 <= len(nums) <= 10
  • Values are distinct

Function contractsubsetsArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…