mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
@ -162,6 +162,29 @@ class Solution:
|
|||||||
low += 1
|
low += 1
|
||||||
high -= 1
|
high -= 1
|
||||||
```
|
```
|
||||||
|
>上一版本简化版
|
||||||
|
'''python
|
||||||
|
class Solution(object):
|
||||||
|
def nextPermutation(self, nums: List[int]) -> None:
|
||||||
|
n = len(nums)
|
||||||
|
i = n-2
|
||||||
|
while i >= 0 and nums[i] >= nums[i+1]:
|
||||||
|
i -= 1
|
||||||
|
|
||||||
|
if i > -1: // i==-1,不存在下一个更大的排列
|
||||||
|
j = n-1
|
||||||
|
while j >= 0 and nums[j] <= nums[i]:
|
||||||
|
j -= 1
|
||||||
|
nums[i], nums[j] = nums[j], nums[i]
|
||||||
|
|
||||||
|
start, end = i+1, n-1
|
||||||
|
while start < end:
|
||||||
|
nums[start], nums[end] = nums[end], nums[start]
|
||||||
|
start += 1
|
||||||
|
end -= 1
|
||||||
|
|
||||||
|
return nums
|
||||||
|
'''
|
||||||
|
|
||||||
## Go
|
## Go
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user