Update 0031.下一个排列.md

fixed bug in python solution and display issues
This commit is contained in:
Caesar-Wei
2022-07-28 22:55:05 -04:00
committed by GitHub
parent b2df4ad5e5
commit 28aef25b61

View File

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