Java solution - from using Stack (62%) to 2-Pointer (100%)
Solution uses Stack\n\nclass Solution {\n\tpublic boolean backspaceCompare(String S, String T) {\n\t\tStack<Character> s = transform(S);\n\t\tStack<Character> t
1. Solution uses Stack\n```\nclass Solution {\n\tpublic boolean backspaceCompare(String S, String T) {\n\t\tStack<Character> s = transform(S);\n\t\tStack<Character> t = transform(T);\n\t\tif (s.size() != t.size()) return false;\n\t\twhile (!s.isEmpty()) {\n\t\t\tif (s.pop() != t.pop())\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tprivate Stack<Character> transform(String S) {\n\t\tStack<Character> stack = new Stack<>();\n\t\tfor (char c : S.toCharArray()) {\n\t\t\tif (c == \'#\') {\n\t\t\t\tif (!stack.isEmpty())\n\t\t\t\t\tstack.pop();\n\t\t\t} else {\n\t\t\t\tstack.push(c);\n\t\t\t}\n\t\t}\n\t\treturn stack;\n\t}\n}\n// Time: O(m+n)\n// Space: O(m+n)\n```\n\n\n\n2. Solution doesn\'t use Stack\n```\nclass Solution {\n\tpublic boolean backspaceCompare(String S, String T) {\n\t\tint i = S.length() - 1;\n\t\tint j = T.length() - 1;\n\t\twhile (i >= 0 || j >= 0) {\n\t\t\ti = backspace(S, i);\n            j = backspace(T, j); \n\t\t\tif (i < 0 && j < 0) return true;\n\t\t\tif (i < 0 || j < 0 || S.charAt(i) != T.charAt(j)) return false;\n\t\t\ti--; j--;\n\t\t}\n\t\treturn true;\n\t}\n    \n    private int backspace(String S, int i) { // back to the remaining character\n        int skip = 0;\n        while (i >= 0 && (skip > 0 || S.charAt(i) == \'#\')) {\n            if (S.charAt(i) == \'#\') skip++;\n            else skip--;\n            i--;\n        }\n        return i;\n    }\n}\n// Time: O(m+n)\n// Space: O(1)\n```\n
[]