Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).
The replacement must be in-place, do not allocate extra memory.
Here are some examples. Inputs are in the left-hand column and its corresponding outputs are in the right-hand column.
1,2,3 → 1,3,2
3,2,1 → 1,2,3
1,1,5 → 1,5,1
{优快云:CODE:633049}

本文介绍了一个算法问题——如何在原地实现数组中数字的下一个字典序排列。如果无法找到更大的排列,则将其重置为最小可能的顺序(升序)。文章通过示例说明了输入输出的变化。
421

被折叠的 条评论
为什么被折叠?



