Skip to content

Instantly share code, notes, and snippets.

@Irene-123
Created August 10, 2020 04:08
Show Gist options
  • Save Irene-123/b33e9d7eb1cdd8da386012aaf3f86087 to your computer and use it in GitHub Desktop.
Save Irene-123/b33e9d7eb1cdd8da386012aaf3f86087 to your computer and use it in GitHub Desktop.
Monotone Increasing Digits
class Solution:
def monotoneIncreasingDigits(self, N: int) -> int:
n=N
if n==10:
return 9
if n<10:
return n
arr=[int(i) for i in str(n)]
for i in range (len(arr)-1):
if arr[i]>arr[i+1]:
while i>0 and arr[i]<=arr[i-1]:
i-=1
arr[i]-=1
for j in range (i+1,len(arr)):
arr[j]=9
res=int(''.join([str(k) for k in arr]))
return res
return n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment