8 lines C++ O(1) space easy to understand
Two Pointers - O(1) space\n\nclass Solution {\npublic:\n    bool backspaceCompare(string S, string T) {\n        int i = S.size() - 1, j = T.size() - 1, countA 
**Two Pointers - O(1) space**\n```\nclass Solution {\npublic:\n    bool backspaceCompare(string S, string T) {\n        int i = S.size() - 1, j = T.size() - 1, countA = 0, countB = 0;\n        while(i >= 0 || j >= 0){\n            while(i >= 0 && (S[i] == \'#\' || countA > 0)) S[i--] == \'#\' ? ++countA : --countA;\n            while(j >= 0 && (T[j] == \'#\' || countB > 0)) T[j--] == \'#\' ? ++countB : --countB;\n            if(i < 0 || j < 0) return i == j;\n            if(S[i--] != T[j--]) return false;\n        }\n        return i == j;\n    }\n};\n```\n***\n**Stack - O(n) space**\n```\nclass Solution {\npublic:\n    bool backspaceCompare(string S, string T) {\n        string a = "", b = "";\n        for(auto c: S) c == \'#\' ? a.size() > 0 ? a.pop_back() : void() : a.push_back(c);\n        for(auto c: T) c == \'#\' ? b.size() > 0 ? b.pop_back() : void() : b.push_back(c);\n        return a == b;\n    }\n};\n```
[]