Using the fact that there are n-1 nodes and n+1 null pointers
\nclass Solution {\npublic:\n    bool isValidSerialization(string preorder) {\n        int count = 0;\n        int n = preorder.length();\n        int i = 0;\n 
```\nclass Solution {\npublic:\n    bool isValidSerialization(string preorder) {\n        int count = 0;\n        int n = preorder.length();\n        int i = 0;\n        for (;i<n;i++)\n        {\n            if(preorder[i] == \',\')\n                continue;\n            if(count<0)\n                return false;\n            if(preorder[i] == \'#\')\n                count--;\n            else\n            {\n                while(i<preorder.length() && preorder[i] != \',\')\n                {\n                    i++;\n                }\n                    count++;\n                \n            }\n        }\n        if(count == -1)\n            return true;\n        return false;\n    }\n};\n```
[]