Simple Python Solution


  • 0
    B

    class Solution(object):
    def monotoneIncreasingDigits(self, N):
    """
    :type N: int
    :rtype: int
    """

        if N == 10:
            return 9
        if N < 20:
            return N
        num = [s for s in str(N)]
        i = len(num) - 1
        index = len(num) 
        while i > 0:
            if int(num[i]) < int(num[i-1]):
                num[i-1] = str(int(num[i-1]) -1)
                index = i
            i -= 1
        for n in range(index,len(num)):
            num[n] = '9'
        return int(''.join(s for s in num))

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.