# LC 3174. Clear Digits
### [Problem link](https://leetcode.com/problems/clear-digits/)
###### tags: `leedcode` `easy` `c++`
You are given a string <code>s</code>.
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.
**Example 1:**
Input: s = "abc"
Output: "abc"
Explanation:
There is no digit in the string.
**Example 2:**
Input: s = "cb34"
Output: ""
Explanation:
First, we apply the operation on <code>s[2]</code>, and <code>s</code> becomes <code>"c4"</code>.
Then we apply the operation on <code>s[1]</code>, and <code>s</code> becomes <code>""</code>.
**Constraints:**
- <code>1 <= s.length <= 100</code>
- <code>s</code> consists only of lowercase English letters and digits.
- The input is generated such that it is possible to delete all digits.
## Solution 1
#### C++
```cpp=
class Solution {
public:
string clearDigits(string s) {
vector<char> st;
for (char& c: s) {
if (st.size() > 0 && isdigit(c)) {
st.pop_back();
} else {
st.push_back(c);
}
}
string res(st.begin(), st.end());
return res;
}
};
```
>### Complexity
>| | Time Complexity | Space Complexity |
>| ----------- | --------------- | ---------------- |
>| Solution 1 | O(n) | O(n) |
## Note
x