Name: Anonymous 2021-03-21 19:34
Implement
If such an arrangement is not possible, it must rearrange it as the lowest possible order (i.e., sorted in ascending order).
The replacement must be in place and use only constant extra memory.
Example 1:
Input:[1,2,3]
Output: [1,3,2]
Example 2:
Input: [3,2,1]
Output: [1,2,3]
Example 3:
Input: [1,1,5]
Output: [1,5,1]
Example 4:
Input: [1]
Output: [1]
Constraints:
Shortest code wins bonus prize, but the main prize goes to every post with actually functioning code.
The deadline is 691200 seconds from this post's timestamp.
next permutation, which rearranges numbers (
nums
) into the lexicographically next greater permutation of numbers.If such an arrangement is not possible, it must rearrange it as the lowest possible order (i.e., sorted in ascending order).
The replacement must be in place and use only constant extra memory.
Example 1:
Input:[1,2,3]
Output: [1,3,2]
Example 2:
Input: [3,2,1]
Output: [1,2,3]
Example 3:
Input: [1,1,5]
Output: [1,5,1]
Example 4:
Input: [1]
Output: [1]
Constraints:
1 <= nums.length <= 10e6
0 <= nums[i] <= 2147483647
Shortest code wins bonus prize, but the main prize goes to every post with actually functioning code.
The deadline is 691200 seconds from this post's timestamp.