Practice/Meta/Leetcode 46. Permutations
CodingOptional
You are given an array of distinct integers. Your task is to return all possible arrangements of these numbers. Each arrangement should include all elements from the original array exactly once, but in a different order.
For example, if given [1, 2, 3], you should return all six ways these three numbers can be ordered: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].
1 <= nums.length <= 6-10 <= nums[i] <= 10nums are uniqueExample 1:
Input: nums = [1, 2, 3] Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] Explanation: There are 6 permutations (3! = 6) of the three numbers
Example 2:
Input: nums = [0, 1] Output: [[0,1],[1,0]] Explanation: Two elements can be arranged in only 2 ways
Example 3:
Input: nums = [1] Output: [[1]] Explanation: A single element has only one possible arrangement