Short Python, one O(n) and one RegEx
O(n) Solution\n\nGo through the digits from left to right, remove previous digits if that makes the number smaller (and if we still have to remove digits). Almo
## O(n) Solution\n\nGo through the digits from left to right, remove previous digits if that makes the number smaller (and if we still have to remove digits). Almost the same as the `prep` function from [my solution to an earlier problem](https://discuss.leetcode.com/topic/32298/short-python-ruby-c), which did basically the same except it **maximized** the number.\n\n    def removeKdigits(self, num, k):\n        out = []\n        for d in num:\n            while k and out and out[-1] > d:\n                out.pop()\n                k -= 1\n            out.append(d)\n        return ''.join(out[:-k or None]).lstrip('0') or '0'\n\n## Regex Solution\n\nk times remove the leftmost digit followed by a smaller digit (or remove the last digit). Didn't think this would be fast enough, but it is :-)\n\n    def removeKdigits(self, num, k):\n        sub = re.compile('1[0]|2[01]|3[0-2]|4[0-3]|5[0-4]|6[0-5]|7[0-6]|8[0-7]|9[0-8]|.$').sub\n        for _ in range(k):\n            num = sub(lambda m: m.group()[1:], num, 1)\n        return num.lstrip('0') or '0'
[]