Permutations
Given an array nums of distinct integers, return all possible permutations. You can return the answer in any order.
Open official problem prompt ↗List every distinct ordering of the input elements, using each element exactly once per ordering.
Seating 3 guests in 3 chairs: for the first chair you have 3 choices, then 2, then 1, tracing out all 6 seating arrangements.
- Input
- nums = [1, 2, 3]
- Output
- [[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]
- Why
- There are 3! = 6 orderings of three distinct elements, and each appears exactly once.
1 <= nums.length <= 6-10 <= nums[i] <= 10All the integers of nums are unique