LeetCode solutions

3447. Clear Digits

My accepted C++ solution to LeetCode problem 3447, Clear Digits, running in 0ms.

  • Difficulty: Easy
  • C++
  • Runtime 0ms
  • Memory 8.5MB

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 0ms, memory 8.5MB, accepted 2025-12-27.

cpp
class Solution {
    public:
    string clearDigits(string s) {
        string result;
        for (char c : s) {
            if (isdigit(c)) {
                if (!result.empty()) result.pop_back();
            } else {
                result += c;
            }
        }
        return result;
    }
};

Source