2 lines Java using Regex
Regex idea from andrei3's solution.\n\n    public boolean isValidSerialization(String preorder) {\n        String s = preorder.replaceAll("\\d+,#,#", "#");\n   
Regex idea from [andrei3's solution](https://leetcode.com/discuss/83896/8-line-regex-solution-without-building-the-tree).\n\n    public boolean isValidSerialization(String preorder) {\n        String s = preorder.replaceAll("\\\\d+,#,#", "#");\n        return s.equals("#") || !s.equals(preorder) && isValidSerialization(s);\n    }
['Java']