Clean sample JAVA solution with explain
public boolean isValidSerialization(String preorder) {\n        String[] chars = preorder.split(",");\n        \n        int sentinel = 0;\n        int node = 0
public boolean isValidSerialization(String preorder) {\n        String[] chars = preorder.split(",");\n        \n        int sentinel = 0;\n        int node = 0;\n        for (int i = chars.length - 1; i >= 0; i--)\n        {\n            if (chars[i].equals("#"))\n            {\n                sentinel++;\n            }\n            else\n            {\n                node++;\n            }\n            if (sentinel - node < 1)\n            {\n                return false;\n            }\n        }\n        return sentinel - node == 1;\n    }\n\n1. Total quantity of sentinel is always nodes\' quantity plus one.\n2. Each time when adding a node to the tree, one more sentinel must be added some where after the node. (image a node replaced a sentinel, but it self has two sentinel)\n3. Browse the string backward follow rule 1 and 2.
[]