Straightforward Java Solution Using Stack
\npublic class Solution {\n    public String removeKdigits(String num, int k) {\n        int len = num.length();\n        //corner case\n        if(k==len)     
```\npublic class Solution {\n    public String removeKdigits(String num, int k) {\n        int len = num.length();\n        //corner case\n        if(k==len)        \n            return "0";\n            \n        Stack<Character> stack = new Stack<>();\n        int i =0;\n        while(i<num.length()){\n            //whenever meet a digit which is less than the previous digit, discard the previous one\n            while(k>0 && !stack.isEmpty() && stack.peek()>num.charAt(i)){\n                stack.pop();\n                k--;\n            }\n            stack.push(num.charAt(i));\n            i++;\n        }\n        \n        // corner case like "1111"\n        while(k>0){\n            stack.pop();\n            k--;            \n        }\n        \n        //construct the number from the stack\n        StringBuilder sb = new StringBuilder();\n        while(!stack.isEmpty())\n            sb.append(stack.pop());\n        sb.reverse();\n        \n        //remove all the 0 at the head\n        while(sb.length()>1 && sb.charAt(0)=='0')\n            sb.deleteCharAt(0);\n        return sb.toString();\n    }\n}\n```
['Java']