Permutations
Generate all n! permutations of an array of distinct integers using used-marker backtracking.
01The problem
Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.
| Input | Output | Why |
|---|---|---|
nums = [1, 2, 3] | [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] | All 3! = 6 unique orderings |
nums = [0, 1] | [[0, 1], [1, 0]] | All 2! = 2 orderings |
nums = [1] | [[1]] | 1 ordering |
Constraints: 1 <= nums.length <= 6, -10 <= nums[i] <= 10, all integers in nums are unique.
Loading the rest of the lesson…