See More

class Solution { public: string removeKdigits(string num, int k) { stack s; int i=0; for( ;i c){ s.pop(); k--; } if (k==0) { break; } else if (s.empty() || s.top() <= c) { s.push(c); } } if (k==0) { for( ;i=0; j--){ str[j] = s.top(); s.pop(); } int lz = findLastZeroIdx(str); switch (lz) { case -2: return "0"; default: return str.substr(lz+1); } } int findLastZeroIdx(string str) { for(int i=0;i