BEATS 100% || STACK BASED SIMPLE IMPLEMENTATION
\n\n# Intuition\nThe code uses a stack to simulate backspace operations for two strings and checks if the processed strings are equal, returning a boolean resul
![image.png](https://assets.leetcode.com/users/images/264c53aa-7acb-493c-9d29-8eaaa8bdb18e_1697682059.6926131.png)\n\n# Intuition\nThe code uses a stack to simulate backspace operations for two strings and checks if the processed strings are equal, returning a boolean result.\n\n# Approach\nThe ***convert*** function processes a given string s:\n- It uses a stack to keep track of the characters in the processed string.\n- It iterates through the characters in s.\n- If it encounters a \'#\' character, it checks if the stack is empty. If it is not empty, it removes the top character (simulating a backspace).\n- Otherwise, it pushes the character onto the stack.\n- After processing all characters, it builds the resulting string a by popping characters from the stack.\n\n# Complexity\n- Time complexity: $$O(n)$$ \n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n    //convert function -- working is stated above\n    string convert(string s)\n    {\n        stack<char>st;//stack of characters\n        for(int i = 0;i<s.length();i++)\n        {\n            if(s[i]==\'#\')\n            {\n                if(st.empty()) continue;// if there is nothing to remove\n                else st.pop();\n            }\n            else\n                st.push(s[i]);\n        }\n        string a = "";\n        while(st.empty()==false)\n        {\n            a+=st.top();\n            st.pop();\n        }\n        return a;\n    }\n    bool backspaceCompare(string s, string t) {\n//convert s & t and compare them\n        string s1 = convert(s);\n        string s2 = convert(t);\n        return s1==s2;\n    }\n};\n```
['Stack', 'C++']