✅ C++|| two pointer||  best solution on leetcode || 0ms solution🔥🔥✅
Intuition\n Describe your first thoughts on how to solve this problem. \n\u2705two pointer approach , best solution on leetcode ,space:O(1) ,time: O(m+n)\u2705\
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n**\u2705two pointer approach , best solution on leetcode ,space:O(1) ,time: O(m+n)\u2705**\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n# Complexity\n- Time complexity: O(m+n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    bool backspaceCompare(string s, string t) {\n        \n        int n1 = s.length();\n        int n2 = t.length();\n\n        int i=0,j=0;\n\n       while(i < n1){\n            if(isalpha(s[i])){\n                i++;\n            }\n            else if(s[i] == \'#\' && i != 0){\n                i++;\n                s.erase(i-2,2);\n                n1 = s.length();\n                i-= 2;\n            }\n            else if(s[i] == \'#\' && i == 0){\n                i++;\n                s.erase(i-1,1);\n                n1 = s.length();\n                i = 0;\n            }\n        }\n\n        while(j < n2){\n            if(isalpha(t[j])){\n                j++;\n            }\n            else if(t[j] == \'#\' && j != 0){\n                j++;\n                t.erase(j-2,2);\n                n2 = t.length();\n                j-= 2;\n            }\n\n            else if(t[j] == \'#\' && j == 0){\n                j++;\n                t.erase(j-1,1);\n                n2 = t.length();\n                j = 0;\n            }\n        }\n\n        return s==t;\n    }\n};\n```\n\n\n![0a95fea4-64f4-4502-82aa-41db6d77c05c_1676054939.8270252.jpeg](https://assets.leetcode.com/users/images/84abbd61-de5a-4565-991b-72e2a3d0085f_1682344552.1590555.jpeg)\n\n\n\n
['Two Pointers', 'C++', 'Java']