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
半天没看懂题
作为数字数组来说,就是用这些数组组成一个数,比当前数字排列大的下一组数字
如果已经是最大的,则是最小的那一组
func nextPermutation(nums []int) {
if len(nums)>1{
l:=0
tmp:=nums[len(nums)-1]
for i:=len(nums)-2;i>=0;i--{
if nums[i]>=tmp{
tmp=nums[i]
}else {
for j:=len(nums)-1;j>0;j--{
if nums[j]>nums[i]{
swap:=nums[i]
nums[i]=nums[j]
nums[j]=swap
l=i+1
break
}
}
break
}
}
r:=len(nums)-1
for l<r{
swap:=nums[r]
nums[r]=nums[l]
nums[l]=swap
l++
r--
}
}
}