87. Permutations

MediumArrayArray

Given an array nums of distinct integers, return all possible permutations in any order.

Input: Integer array nums of distinct integers.

Output: All permutations sorted lexicographically.

Examples

Example 1
Input: [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 permutations.
Example 2
Input: [0,1]
Output: [[0,1],[1,0]]
Explanation: 2! permutations.
Example 3
Input: [1]
Output: [[1]]
Explanation: 1! permutation.

Constraints

Asked by

ZomatoAmazonMicrosoftBloombergGoogleInfosys
Solve this problem in the editor →