Java Solution with Stack
\nclass Solution {\n    public boolean isValidSerialization(String preorder) {\n        Stack<String> stack = new Stack<>();\n        String[] res = preorder.sp
```\nclass Solution {\n    public boolean isValidSerialization(String preorder) {\n        Stack<String> stack = new Stack<>();\n        String[] res = preorder.split(",");\n        for(String r : res){\n            while("#".equals(r) && !stack.isEmpty() && "#".equals(stack.peek())){\n                stack.pop();\n                if(stack.isEmpty()) return false;\n                stack.pop();\n            }\n            stack.push(r);\n        }\n        return stack.size()==1 && "#".equals(stack.peek());\n    }\n}\n```
['Stack', 'Java']