最后一个5000个全1的超时了。。。
class Solution {
public:
string removeKdigits(string num, int k) {
int n = num.size();
if(k >= n){
return "0";
}
stack<char> stk;
for(int i = 0; i < n; ++i){
while(stk.size() > 0 && num[i] < stk.top() && k){
stk.pop();
--k;
}
stk.push(num[i]);
}
while(k--){
stk.pop();
}
string res = "";
while(!stk.empty()){
res = stk.top() + res;
stk.pop();
}
while(res.size() > 0){
if(res[0] == '0'){
res.erase(res.begin());
}else{
break;
}
}
return res == "" ? "0" : res;
}
};