[Java/C++/Python] O(N) time and O(1) space
Intuition\nThe intuition and quick methode is to find the final text result.\nYou can just use a string if you don\'t care cost on string modification.\nOr you 
# **Intuition**\nThe intuition and quick methode is to find the final text result.\nYou can just use a string if you don\'t care cost on string modification.\nOr you can use a stack or string builder to do it in O(N).\n\nUse stack to avoid string modification. \nTime O(N) and space O(N).\n```py\n    def backspaceCompare(self, S, T):\n        def back(res, c):\n            if c != \'#\': res.append(c)\n            elif res: res.pop()\n            return res\n        return reduce(back, S, []) == reduce(back, T, [])\n```\n<br>\n\n# Follow up: O(1) Space\nCan you do it in O(N) time and O(1) space?\nI believe you have one difficulty here:\nWhen we meet a char, we are not sure if it will be still there or be deleted.\n\nHowever, we can do a back string compare (just like the title of problem).\nIf we do it backward, we meet a char and we can be sure this char won\'t be deleted.\nIf we meet a \'#\', it tell us we need to skip next lowercase char.\n\nThe idea is that, read next letter from end to start.\nIf we meet `#`, we increase the number we need to step back, until `back = 0`\n<br>\n\n**C++:**\n```cpp\n    bool backspaceCompare(string S, string T) {\n        int i = S.length() - 1, j = T.length() - 1, back;\n        while (true) {\n            back = 0;\n            while (i >= 0 && (back > 0 || S[i] == \'#\')) {\n                back += S[i] == \'#\' ? 1 : -1;\n                i--;\n            }\n            back = 0;\n            while (j >= 0 && (back > 0 || T[j] == \'#\')) {\n                back += T[j] == \'#\' ? 1 : -1;\n                j--;\n            }\n            if (i >= 0 && j >= 0 && S[i] == T[j]) {\n                i--;\n                j--;\n            } else {\n                break;\n            }\n        }\n        return i == -1 && j == -1;\n    }\n```\n\n**Java:**\n```java\n    public boolean backspaceCompare(String S, String T) {\n        int i = S.length() - 1, j = T.length() - 1, back;\n        while (true) {\n            back = 0;\n            while (i >= 0 && (back > 0 || S.charAt(i) == \'#\')) {\n                back += S.charAt(i) == \'#\' ? 1 : -1;\n                i--;\n            }\n            back = 0;\n            while (j >= 0 && (back > 0 || T.charAt(j) == \'#\')) {\n                back += T.charAt(j) == \'#\' ? 1 : -1;\n                j--;\n            }\n            if (i >= 0 && j >= 0 && S.charAt(i) == T.charAt(j)) {\n                i--;\n                j--;\n            } else {\n                break;\n            }\n        }\n        return i == -1 && j == -1;\n    }\n```\n**Python:**\n```py\n    def backspaceCompare(self, S, T):\n        i, j = len(S) - 1, len(T) - 1\n        backS = backT = 0\n        while True:\n            while i >= 0 and (backS or S[i] == \'#\'):\n                backS += 1 if S[i] == \'#\' else -1\n                i -= 1\n            while j >= 0 and (backT or T[j] == \'#\'):\n                backT += 1 if T[j] == \'#\' else -1\n                j -= 1\n            if not (i >= 0 and j >= 0 and S[i] == T[j]):\n                return i == j == -1\n            i, j = i - 1, j - 1\n```\n\n**Python:**\n```py\n    def backspaceCompare(self, S, T):\n        back = lambda res, c: res[:-1] if c == \'#\' else res + c\n        return reduce(back, S, "") == reduce(back, T, "")\n```
[]