R3-字符串

思路:
0-10直接返回-1得了
然后尽量倒数后两位的数值,查看是否变大,再逆序,怎么有点像指针?。
class Solution: def nextGreaterElement(self, n: int) -> int: def nextMax(nums): n=len(nums) index=-1 for i in range(n-2,-1,-1): if nums[i]nums[index]: nums[i],nums[index]=nums[index],nums[i] break #除了爆破位置数字,后面的都要逆序 left,right=index+1,n-1 while leftn: return ret else: return -1 
ps:
#将数字变为列表来使用 nums=list(map(int,list(str(n)))) #将列表转换回数字 ret=int("".join(map(str,num))) 列表逆序
nums.reverse() python交换数字
a,b=b,a python逆序,也可以使用切片操作
#除了爆破位置数字,后面的都要逆序 left,right=index+1,n-1 while left