Simple recursive solution, easy to understand
Basically we simulate the preorder traversal in the recursive way while moving along on the string tokens. After the traversal is done, if we also exhaust the t
Basically we simulate the preorder traversal in the recursive way while moving along on the string tokens. After the traversal is done, if we also exhaust the tokens, no more no less, then it is a valid serialization.\n\n    public class Solution {\n        int reach(String[] tokens, int start) {\n            if (start >= tokens.length) return -1;\n            if (tokens[start].equals("#")) return start+1;\n            int rl = reach(tokens, start+1);\n            if (rl < 0) return -1;\n            return reach(tokens, rl);\n        }\n        public boolean isValidSerialization(String preorder) {\n            String[] tokens = preorder.split(",");\n            return reach(tokens, 0) == tokens.length;\n        }\n    }
[]