C++ (recursive and iteration)
iteration\n\nclass Solution {\npublic:\n    string removeKdigits(string num, int k) {\n        if (0 == k) {\n            return num;\n        }\n        if (nu
* iteration\n```\nclass Solution {\npublic:\n    string removeKdigits(string num, int k) {\n        if (0 == k) {\n            return num;\n        }\n        if (num.size() <= 1) {\n            num = "0";\n            return num;\n        }\n        int i, j;\n        for (i = 0; i < k; ++i) {\n            for (j = 0; j + 1 < num.size(); ++j) {\n                if (num[j] > num[j + 1]) {\n                    break;\n                }\n            }\n            if (num.size() > 0) {\n                num.erase(j, 1);\n            }\n        }\n        while (num.size() > 0 && num[0] == \'0\') {\n            num.erase(0, 1);\n        }\n        if (num.size() == 0) {\n            num = "0";\n        }\n        return num;\n    }\n};\n```\n* recursive\n```\nclass Solution {\npublic:\n    string removeKdigits(string num, int k) {\n        if (0 == k) {\n            return num;\n        }\n        \n        size_t i;\n        for (i = 0; i + 1 < num.size(); ++i) {\n            if (num[i] > num[i + 1]) {\n                break;\n            }\n        }\n        if (num.size() > 0) {\n            num.erase(i, 1);\n        }\n        while (num.size() > 0 && num[0] == \'0\') {\n            num.erase(0, 1);\n        }\n        if (num.size() == 0) {\n            num = "0";\n            return num;\n        }\n        return removeKdigits(num, k - 1);\n    }\n};\n```
[]