Just  string  problem  8 lines and 4 ms .this C++  code is very easy to understand.
class Solution {\n    public:\n    \tbool isValidSerialization(string preorder) {\n    \t\tint i, nul = 0, node = 1;\n    \t\tfor (i = 0; i < preorder.length();
    class Solution {\n    public:\n    \tbool isValidSerialization(string preorder) {\n    \t\tint i, nul = 0, node = 1;\n    \t\tfor (i = 0; i < preorder.length(); ++i){\n    \t\t\tif (preorder[i] == ',')node++;\n    \t\t\tif (preorder[i] == '#')nul++;\n    \t\t\tif (2 * nul == node + 1 && i != preorder.length() - 1)return false;\n    \t\t}\n    \t\treturn 2 * nul == node + 1;\n    \t}\n    };
[]