题目:3174. 清除数字
思路:用字符串t模拟操作要求,当x是数字时,删除t的最后一个字符。不是的话,直接插入x
class Solution {
public:
string clearDigits(string s) {
string t="";
for(auto x:s){
if('0'<=x&&x<='9'){
if(t.size()) t.pop_back();
}else{
t.push_back(x);
}
}
return t;
}
};
标签:数字,清除,back,LeetCode,字符串,3174,string
From: https://blog.csdn.net/weixin_46028214/article/details/141930148