Python using stack
Had to say it took me a while to think through this problem. And I really had no clue until saw the problem is tagged under stack, sigh... \n\nAnyway, here is m
Had to say it took me a while to think through this problem. And I really had no clue until saw the problem is tagged under ```stack```, sigh... \n\nAnyway, here is my solution using stack. The key idea is make the current total number in the ```stack``` as small as possible. Since the leftmost digit matters most, when current digit ```x``` is smaller than ```stack[-1]``` and we have available budget ```k```, we pop out the last digit of the ```stack```. Keep in mind we need to consider the case when k is too large (i.e. there is still k available after the ```for``` loop).\n```\nclass Solution(object):\n    def removeKdigits(self, num, k):\n        """\n        :type num: str\n        :type k: int\n        :rtype: str\n        """\n        stack = []\n        for x in num:\n            while stack and stack[-1] > x and k:\n                stack.pop()\n                k -= 1\n            stack.append(x)\n            \n        return "".join(stack[:len(stack)-k]).lstrip("0") or "0"\n```
[]