Problem
Given an array nums of distinct integers, return all possible permutations of the array.
A permutation is an ordering of all elements in the array, and each element must appear exactly once in each permutation.
Input
-
nums
: an array of integers with no duplicates.
Output
-
A list of permutations, where each permutation is a list/array of integers.
-
You may return the permutations in
any order
.
Constraints
-
1 <= nums.length <= 10
-
-10 <= nums[i] <= 10
-
All values in
nums
are unique.
Example
Input: nums = [1,2,3]
Output (one valid ordering):
[
[1,2,3],
[1,3,2],
[2,1,3],
[2,3,1],
[3,1,2],
[3,2,1]
]
Notes
-
Aim for a solution using DFS/backtracking.
-
Consider how to track which elements have been used in the current partial permutation.