Traversal solution but not building a tree
```\npublic class Solution {\n    int idx;\n    public boolean isValidSerialization(String preorder) {\n        String[] strs = preorder.split(",");\n        if
```\npublic class Solution {\n    int idx;\n    public boolean isValidSerialization(String preorder) {\n        String[] strs = preorder.split(",");\n        if (strs.length == 0) return true;\n        if (strs.length == 1) {\n            if (strs[0].equals("#")) return true;\n            else return false;\n        }\n        idx = 0;\n        return preorder(strs) && (idx == strs.length);\n    }\n    boolean preorder(String[] strs) {\n        if (idx == strs.length) return true;\n        if (strs[idx].equals("#")) {\n            idx++;\n            return true;\n        }\n        idx++;\n        if (idx == strs.length) return false;\n        boolean left = preorder(strs);\n        if (idx == strs.length) return false;\n        boolean right = preorder(strs);\n        return left && right;\n    }\n}
[]