Medium · Arrays
Next permutation
Given an integer array nums, rearrange it in place into the next lexicographically greater permutation; if nums is already the largest arrangement (non-increasing), rearrange it into ascending order. Nothing is returned: nums itself is the result.
Examples
Example 1
[1,2,3]Output: [1,3,2]
Example 2
[1,3,5,4,2]Output: [1,4,2,3,5]
Rebuild it in the studio
Open every published interview problem, solution, scene, and memory room free, with no account.