Java Stack and StringBuilder Solution (Huge different)
StringBuilder Solution\nRuntime: 0 ms, runtime beats 100.00 % of java submissions\nMemory Usage: 34.3 MB\n\n    public boolean backspaceCompare(String S, String
***StringBuilder Solution***\nRuntime: 0 ms, runtime beats 100.00 % of java submissions\nMemory Usage: 34.3 MB\n```\n    public boolean backspaceCompare(String S, String T) {\n        return sb(S).equals(sb(T));\n    }\n    \n    private String sb(String str) {\n        StringBuilder sbr = new StringBuilder();\n        \n        for (char c : str.toCharArray()) {\n            \n            if (c != \'#\') {\n                sbr.append(c);\n            } else if (sbr.length() != 0) {\n                sbr.deleteCharAt(sbr.length() - 1);\n            }\n        }\n        return sbr.toString();\n    }\n```\n\n***Stack Solution***\nRuntime: 2 ms, faster than 49.13% of Java online submissions\nMemory Usage: 35.8 MB, less than 72.73% of Java online submissions\n```\n    public boolean backspaceCompare(String S, String T) {\n        return stackSolution(S).equals(stackSolution(T));\n    }\n    \n    private String stackSolution(String str) {\n        Stack<Character> stack = new Stack<Character>();\n        \n        for (char c : str.toCharArray()) {\n\t\t\n            if (c != \'#\') {\n                stack.push(c);\n\t\t\t\t\n            } else if (!stack.isEmpty()) {\n                stack.pop();\n            }\n        }\n        return stack.toString();\n    }\n```
['Java']