You are given a string s.
Your task is to remove all digits by doing this operation repeatedly:
Delete the first digit and the closest non-digit character to its left.
Return the resulting string after removing all digits.
class Solution {
public:
string clearDigits(string s) {
int i = 0;
int n = s.length();
while (i < n) {
if (s[i] <= '9' && s[i] >= '0') {
s[i] = '!';
for (int j = i - 1; j >= 0; j--) {
if ((s[j] > '9' || s[j] < '0') && s[j] != '!') {
s[j] = '!';
break;
}
}
}
i++;
}
string res = "";
for (int k = 0; k < n; k++) {
if (s[k] != '!') res += s[k];
}
return res;
}
};