# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @return int整型一维数组 # class Solution: def nextPermutation(self , nums: List[int]) -> List[int]: # write code here n = len(nums) firstless = -1 for i in range(n-2,-1,-1): if nums[i] <nums[i+1]: firstless = i break if firstless == -1: return nums[::-1] else: for i in range(n-1,firstless,-1): if nums[i] >nums[firstless]: nums[i],nums[firstless] = nums[firstless],nums[i] break nums[firstless+1:n] = list(reversed(nums[firstless+1:n])) return nums