A permutation of an array of integers is an arrangement of its members into a sequence or linear order. The next permutation of an array of integers is the next lexicographically greater permutation of its integer. If such arrangement is not possible, it must be rearranged as the lowest possible order (i.e., sorted in ascending order). The replacement must be in place and use only constant extra memory.
- An array of integers
nums.
Input: nums = [1, 2, 3]
Output: [1, 3, 2]
Input: nums = [3, 2, 1]
Output: [1, 2, 3]