Simple java sol without tree construction
The main thought is to keep track of 'opens' which is number of leaves that this tree can have. To have a valid tree, one have to satisfy the follow two constra
The main thought is to keep track of 'opens' which is number of leaves that this tree can have. To have a valid tree, one have to satisfy the follow two constrains.\nFirst constrain: during the process, opens must be positive.\nSecond constrain: at the end, opens should be zero.\n\n    public class Solution {\n    public boolean isValidSerialization(String preorder) {\n        String[] strs = preorder.split(",");\n        int opens=1;\n        int i;\n        for(i = 0; i < strs.length && opens > 0; i++) {\n            if(strs[i].compareTo("#") == 0)\n                opens--;\n            else\n                opens++;\n        }\n        return (opens == 0 && i == strs.length);\n    }\n}
['Binary Tree', 'Java']