Problem
Think of all arrangements of a list of numbers sorted like words in a dictionary (lexicographic order). Given nums, rearrange it in place into the next greater arrangement. If nums is already the largest arrangement, rearrange it into the smallest one (sorted ascending). Use only O(1) extra memory and return nothing.
Example 1
- Input
- nums = [1, 2, 3]
- Output
- nums becomes [1, 3, 2]
Example 2
- Input
- nums = [3, 2, 1]
- Output
- nums becomes [1, 2, 3]
- Why
- wraps around
Example 3
- Input
- nums = [1, 1, 5]
- Output
- nums becomes [1, 5, 1]
Constraints
1 <= nums.length <= 1000 <= nums[i] <= 100