Merge pull request #1551 from Caesar-Wei/patch-3

Update 0031.下一个排列.md
This commit is contained in:
程序员Carl
2022-08-13 10:21:00 +08:00
committed by GitHub

View File

@ -178,10 +178,10 @@ class Solution:
>另一种思路 >另一种思路
```python ```python
class Solution: class Solution:
''' '''
抛砖引玉因题目要求“必须原地修改只允许使用额外常数空间”python内置sorted函数以及数组切片+sort()无法使用。 抛砖引玉因题目要求“必须原地修改只允许使用额外常数空间”python内置sorted函数以及数组切片+sort()无法使用。
故选择另一种算法暂且提供一种python思路 故选择另一种算法暂且提供一种python思路
''' '''
def nextPermutation(self, nums: List[int]) -> None: def nextPermutation(self, nums: List[int]) -> None:
""" """
Do not return anything, modify nums in-place instead. Do not return anything, modify nums in-place instead.
@ -195,9 +195,9 @@ class Solution:
break break
self.reverse(nums, i, length-1) self.reverse(nums, i, length-1)
break break
else: if n == 1:
# 若正常结束循环,则对原数组直接翻转 # 若正常结束循环,则对原数组直接翻转
self.reverse(nums, 0, length-1) self.reverse(nums, 0, length-1)
def reverse(self, nums: List[int], low: int, high: int) -> None: def reverse(self, nums: List[int], low: int, high: int) -> None:
while low < high: while low < high: