Asked at
Permutations
MediumVerifiedBacktrackingArrayRecursion~20 min
Given an array of distinct integers nums, return all possible permutations.
Return them in any order; the answer must contain no duplicates.
The input arrives as a single array nums.
Examples
in[1, 2, 3]
out[[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]
All 3! = 6 orderings of the three elements.
in[0, 1]
out[[0,1], [1,0]]
Two orderings of two elements.
Constraints
- 1 ≤ nums.length ≤ 7
- -10 ≤ nums[i] ≤ 10
- All numbers are distinct.
Get help
🔑
Sign in to solve
Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.