Loading...
Given an array nums of distinct integers, return every ordering of nums, meaning every arrangement that uses each element exactly once. An array of length n has exactly n! of them.
To make the answer unique, return the orderings in ascending lexicographic order: compare two orderings element by element from the front, and the one with the smaller value at the first differing position comes first. Under this rule the ascending sort of nums is always first and the descending sort is always last.
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: All 3! = 6 orderings, listed lexicographically. The three starting with 1 come first, then those starting with 2, then those starting with 3.
Input: nums = [0,1]
Output: [[0,1],[1,0]]
Input: nums = [1]
Output: [[1]]
Explanation: A single element has exactly one ordering.
nums.length ≤6nums[i] ≤10nums are unique.Click "Run" to test with sample cases or "Submit" to run all tests.