We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c6fadbd commit 912e274Copy full SHA for 912e274
problems/0031.下一个排列.md
@@ -165,6 +165,29 @@ class Solution:
165
low += 1
166
high -= 1
167
```
168
+>上一版本简化版
169
+'''python
170
+class Solution(object):
171
+ def nextPermutation(self, nums: List[int]) -> None:
172
+ n = len(nums)
173
+ i = n-2
174
+ while i >= 0 and nums[i] >= nums[i+1]:
175
+ i -= 1
176
+
177
+ if i > -1: // i==-1,不存在下一个更大的排列
178
+ j = n-1
179
+ while j >= 0 and nums[j] <= nums[i]:
180
+ j -= 1
181
+ nums[i], nums[j] = nums[j], nums[i]
182
183
+ start, end = i+1, n-1
184
+ while start < end:
185
+ nums[start], nums[end] = nums[end], nums[start]
186
+ start += 1
187
+ end -= 1
188
189
+ return nums
190
+'''
191
192
## Go
193
0 commit comments