Untitled

 avatar
user_9124840
plain_text
4 months ago
443 B
3
Indexable
class Solution {
public:
    bool backspaceCompare(string s, string t) {
        return afterBackspacing(s) == afterBackspacing(t);
    }
    string afterBackspacing(string s) {
        string temp = "";
        for (char ch : s) {
            if (ch == '#') {
                if (!temp.empty())
                    temp.pop_back();
            } else
                temp.push_back(ch);
        }
        return temp;
    }
};
Leave a Comment