diff --git a/problems/0031.下一个排列.md b/problems/0031.下一个排列.md index 470c354d..9999486e 100644 --- a/problems/0031.下一个排列.md +++ b/problems/0031.下一个排列.md @@ -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: '''