class Solution { public: string removeKdigits(string num, int k) { int n=num.size(); string ans; int p=0; int c=n-k;//挑c个 for(int i=0;i<c;i++){ string::iterator iter=min_element(num.begin()+p,num.end()-c+i+1); ans.push_back(*iter); p=iter-num.begin()+1; } while(ans[0]=='0')ans.erase(ans.begin()); if(ans.empty()) return{"0"}; return ans; } };