using the property of full binary tree -> noOfLeafNodes = no of internalNodes+1
\nclass Solution {\npublic:\n    bool isValidSerialization(string preorder) {\n        int internalNodes = 0,leafNodes = 0, n = preorder.length();\n        for(
```\nclass Solution {\npublic:\n    bool isValidSerialization(string preorder) {\n        int internalNodes = 0,leafNodes = 0, n = preorder.length();\n        for(int i=0;i<n;i++){\n            if(leafNodes>internalNodes)\n                return false;\n            if(preorder[i]==\'#\')leafNodes++;\n            else\n                internalNodes++;\n            while(i<n && preorder[i]!=\',\')\n                i++;\n        }\n        return (leafNodes==internalNodes+1);\n    }\n};\n```
[]