Easy Python Solution O(nk)


  • 0
    class Solution(object):
        def removeKdigits(self, num, k):
            num = list(num)
            for _ in range(k):
                i = 0
                while i < len(num)-1:
                    if num[i] > num[i+1]:
                        num.pop(i)
                        i = -1
                        break
                    i += 1
                if i >= 0:
                    num.pop()
            return str(int(''.join(num))) if num else '0'

Log in to reply
 

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