Last active
July 28, 2018 21:31
-
-
Save cashlo/31f64b99892a6bd4fa8d4eced333ee43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def nextPermutation(self, nums): | |
""" | |
:type nums: List[int] | |
:rtype: void Do not return anything, modify nums in-place instead. | |
""" | |
if len(nums) == 1: return | |
for i in range(len(nums)-2, -1, -1): | |
if nums[i] < nums[i+1]: | |
m = min((n, -(j+i+1)) for j,n in enumerate(nums[i+1:]) if n > nums[i]) | |
nums[i], nums[-m[1]] = nums[-m[1]], nums[i] | |
nums[i+1:] = nums[len(nums)-1:i:-1] | |
return | |
nums.sort() | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment