题目:给出一个正整数数组,找出该数组按照字典序的下一个排列,如果不存在(比如:987654321)就返回该数组最小的全排列(此时返回:123456789)。
原题目地址:LeetCode--31. Next Permutation
原题目描述:
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 and use only constant 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