Given an array of distinct integers, return all possible permutations.
The runner accepts the permutations in any order.
Build one partial choice at a time, recurse, then undo that choice before exploring the next option. Pay close attention to duplicate handling and stopping conditions.
Examples
Input: nums = [1,2,3] Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
Input: nums = [0,1] Output: [[0,1],[1,0]]
Constraints
- 1 <= nums.length <= 6
- -10 <= nums[i] <= 10
- All elements are unique.