mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Update 0031.下一个排列.md
补充python sorted()代码
This commit is contained in:
@ -120,7 +120,22 @@ class Solution {
|
||||
```
|
||||
|
||||
## Python
|
||||
|
||||
>直接使用sorted()不符合题意
|
||||
```python
|
||||
class Solution:
|
||||
def nextPermutation(self, nums: List[int]) -> None:
|
||||
"""
|
||||
Do not return anything, modify nums in-place instead.
|
||||
"""
|
||||
for i in range(len(nums)-1, -1, -1):
|
||||
for j in range(len(nums)-1, i, -1):
|
||||
if nums[j] > nums[i]:
|
||||
nums[j], nums[i] = nums[i], nums[j]
|
||||
nums[i+1:len(nums)] = sorted(nums[i+1:len(nums)])
|
||||
return
|
||||
nums.sort()
|
||||
```
|
||||
>另一种思路
|
||||
```python
|
||||
class Solution:
|
||||
'''
|
||||
|
Reference in New Issue
Block a user