JAVA | Stack ✅
Please Upvote :D\n\nclass Solution {\n    public String removeKdigits(String num, int k) {\n        if(k == num.length()) return "0";\n\n        Stack<Character
### **Please Upvote** :D\n```\nclass Solution {\n    public String removeKdigits(String num, int k) {\n        if(k == num.length()) return "0";\n\n        Stack<Character> stack = new Stack<>();\n        int i = 0;\n\t\t\n        while (i < num.length()) {\n            while (!stack.isEmpty() && k > 0 && stack.peek() > num.charAt(i)) {\n                stack.pop();\n                k--;\n            }\n\n            stack.push(num.charAt(i));\n            i++;\n        }\n\n        while (k-- > 0) stack.pop();\n\n        StringBuilder sb = new StringBuilder();\n        for (char c : stack) sb.append(c);\n\n        while (sb.length() > 1 && sb.charAt(0) == \'0\') {\n            sb.deleteCharAt(0);\n        }\n\n        return sb.toString();\n    }\n}\n\n// TC: O(n), SC: O(n)\n```
['Stack', 'Java']