Medium
Rearrange nums into the lexicographically next greater permutation. If no greater permutation exists, rearrange to the lowest order (sorted ascending). Return the resulting array. Do it in-place with O(1) extra memory.
Input: nums = [1,2,3] Output: [1,3,2]
Input: nums = [3,2,1] Output: [1,2,3]
Input: nums = [1,1,5] Output: [1,5,1]