Go 语言实现next_permutation
func reverse(nums[]int,l,r int){
for l<r{
nums[l],nums[r]=nums[r],nums[l]
l++
r--
}
}
func next_permutation(nums[]int)bool{
right:=len(nums)-1
for right>0&&nums[right]<=nums[right-1]{
right--
}
if right==0{
return false
}
process:=right-1
for i:=len(nums)-1;i>privot;i--{
if nums[i]>nums[privot]{
nums[privot],nums[i]=nums[i],nums[privot]
break
}
}
reverse(nums,privot+1,len(nums)-1)
return true
}