Simple Python Solution


  • 0
    E
    class Solution(object):
        def removeKdigits(self, num, k):
            if k >= len(num):
                return '0'
            elif k == 0:
                return num
            else:
                num_list = list(num)
                while k > 0:
                    let_index = 0
                    while let_index < len(num_list)-1 and num_list[let_index] <= num_list[let_index+1]:
                        let_index += 1
                    del num_list[let_index]
                    k -= 1
                result = str(int(''.join(num_list)))
                return result
    

Log in to reply
 

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