O(n) time, O(1) memory, C++
\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\npublic:\n    void skipBackspaces(const string& s, int& i) {
\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    void skipBackspaces(const string& s, int& i) {\n        int cnt = 0;\n        while (0 <= i && (s[i] == \'#\' || cnt != 0)) {\n            if (s[i] == \'#\') {\n                ++cnt;\n            } else {\n                --cnt;\n            }\n\n            --i;\n        }\n    }\n\n    bool backspaceCompare(string& s, string& t) {\n        int l = s.size() - 1;\n        int r = t.size() - 1;\n\n        for (; 0 <= l && 0 <= r;) {\n            skipBackspaces(s, l);\n            skipBackspaces(t, r);\n     \n            if (!(0 <= l && 0 <= r)) {\n                break;\n            }\n\n            if (s[l] != t[r]) {\n                return false;\n            }\n\n            --l;\n            --r;\n        }\n\n        skipBackspaces(s, l);\n        skipBackspaces(t, r);\n\n        return l < 0 && r < 0;\n    }\n};\n```
['C++']