title: LEETCODE-DAY37
date: 2024-03-28 17:52:37
tags:
今日内容:
T1
class Solution:
def monotoneIncreasingDigits(self, n: int) -> int:
res=0
number=[int(x) for x in str(n)]
if number==sorted(number):
return n
else:
number[0]=number[0]-1
res=number[0]*(10**(len(number)-1))
for i in range(1,len(number)):
number[i]=9
res+=number[i]*(10**(len(number)-i-1))
return res
输入
n =120
输出
99
预期结果
119
从第一个不递增的开始-1并替换后面的为9