C++ 2 approaches (1. Using stacks, 2. Without stack (but a string))
\n//Approach-1 (Using two stacks)\nclass Solution {\npublic:\n    bool backspaceCompare(string s, string t) {\n        stack<char> s1;\n        stack<char> s2;\
```\n//Approach-1 (Using two stacks)\nclass Solution {\npublic:\n    bool backspaceCompare(string s, string t) {\n        stack<char> s1;\n        stack<char> s2;\n        \n        for(const char& ch : s) {\n            if(ch != \'#\')        s1.push(ch);\n            else if(!s1.empty()) s1.pop();\n        }\n        \n        for(const char& ch : t) {\n            if(ch != \'#\')        s2.push(ch);\n            else if(!s2.empty()) s2.pop();\n        }\n        \n        return s1==s2;\n    }\n};\n```\n\n```\n//Approach-2 (without using stacks, but space complexity is same)\nclass Solution {\npublic:\n    bool backspaceCompare(string s, string t) {\n        string s1 = "";\n        string s2 = "";\n        int k     = 0;\n        for(int i = s.length()-1; i>=0; i--) {\n            if(s[i] == \'#\')\n                k++;\n            else if(k == 0) {\n                s1.push_back(s[i]);\n            } else {\n                k--;\n            }\n        }\n        k = 0;\n        for(int i = t.length()-1; i>=0; i--) {\n            if(t[i] == \'#\')\n                k++;\n            else if(k == 0) {\n                s2.push_back(t[i]);\n            } else {\n                k--;\n            }\n        }\n        \n        return s1 == s2;\n    }\n};\n```
[]