Permutations

Medium

Given an array nums of distinct integers, return all of its permutations in any order.

Example 1

permute()
Input
nums = [0,1]
Output
[[0,1],[1,0]]

Example 2

permute()
Input
nums = [1]
Output
[[1]]
Constraints
1 <= nums.length <= 6
All integers in `nums` are unique.

Topics

BacktrackingRecursionArrays

Implement permute in the editor and return the answer — printing it is never graded.