Skip to content

Latest commit

 

History

History
28 lines (20 loc) · 590 Bytes

738.-monotone-increasing-digits.md

File metadata and controls

28 lines (20 loc) · 590 Bytes

738. Monotone Increasing Digits

class Solution:
    def monotoneIncreasingDigits(self, N: int) -> int:

        N = [x for x in str(N)]
        print(N)
        idx = 1
        while idx < len(N) and N[idx] >= N[idx - 1]:
            idx += 1

        if idx < len(N):
            while idx > 0 and N[idx] < N[idx - 1]:
                N[idx-1] = chr(ord(N[idx-1]) - 1)
                idx -= 1
            # print(idx, N)
            idx = idx + 1 
            while idx  < len(N):

                N[idx] = "9"
                idx += 1


        return int("".join(N))