Back to DSA
Permutations
mediumGiven an array of distinct integers, generate every possible ordering (permutation) of those integers. The results may appear in any sequence.
Examples
Example 1:
Input:
nums = [7,8,9]Output:
[[7,8,9],[7,9,8],[8,7,9],[8,9,7],[9,7,8],[9,8,7]] Example 2:
Input:
nums = [4,5]Output:
[[4,5],[5,4]]Hints
1234567