Generate Subsets - aloalgo.com

Generate Subsets

Medium
New!

You are given an integer array nums of unique elements.

Your task is to return all possible subsets (also known as the power set) of nums.

Remember that:

  • The solution set must not contain duplicate subsets.
  • You can return the solution in any order.

Return a list of lists, where each inner list represents a unique subset.

Example 1

Input
[0]
Output
[
  [],
  [0]
]
Explanation:

The subsets of a single-element set are the empty set and the set containing the element itself.

Example 2

Input
[0, 1]
Output
[
  [],
  [0],
  [1],
  [0, 1]
]
Explanation:

The subsets of the set [0, 1] are the empty set, the single-element sets, and the full set.

Example 3

Input
[0, 1, 2]
Output
[
  [],
  [0],
  [1],
  [2],
  [0, 1],
  [0, 2],
  [1, 2],
  [0, 1, 2]
]
Explanation:

These are all the possible subsets of the input array. The order of the subsets in the output does not matter.

Loading...

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!