4ms C++ solution without using stack
class Solution {\n    public:\n    bool isValidSerialization(string preorder) { \n        int n=preorder.size();\n        int num=0,ctr=0;\n        for(int i=0;
    class Solution {\n    public:\n    bool isValidSerialization(string preorder) { \n        int n=preorder.size();\n        int num=0,ctr=0;\n        for(int i=0;i<n;i++){\n            if(preorder[i]=='#') ctr++;\n            else if(preorder[i]!=','){\n                num++;\n                while(i+1<n&&preorder[i+1]>='0'&&preorder[i+1]<='9') i++;\n            }\n            if(ctr==num+1&&i<n-1) return false;\n        }\n        if(ctr==num+1) return true;\n        else return false;\n    }\n};
[]