Generate Permutations - aloalgo

Generate Permutations

Medium

You are given an array nums of distinct integers.

Your task is to find and return all possible unique permutations of the integers within nums.

Note that:

  • The input array nums contains distinct integers.
  • The order of the returned permutations does not matter.

Return a list containing all possible unique permutations.

Example 1

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

An array with a single element has only one permutation, which is itself.

Example 2

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

For two distinct numbers, there are two possible arrangements.

Example 3

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

For three distinct numbers, there are six possible arrangements.

Loading...
Input
[0]
Output
[
  [0]
]

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!