-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path31.py
More file actions
22 lines (20 loc) · 676 Bytes
/
Copy path31.py
File metadata and controls
22 lines (20 loc) · 676 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import sys
class Solution:
def nextPermutation(self, nums):
"""
:type nums: List[int]
:rtype: void Do not return anything, modify nums in-place instead.
"""
m, size = len(nums) - 2, len(nums)
while m >= 0:
if nums[m] < nums[m + 1]:
break
m -= 1
if(m >= 0):
upper, index = sys.maxsize, 0
for i in range(m + 1, size):
if nums[i] > nums[m] and upper > nums[i]:
upper = nums[i]
index = i
nums[m], nums[index] = nums[index], nums[m]
nums[m + 1: size] = sorted(nums[m + 1: size])