Beats 100% | 0ms solution
Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\npublic:\n    bool isValidSerialization(string preorder) {\n    
# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n    bool isValidSerialization(string preorder) {\n        if(preorder.size() == 0)\n        return false;\n        if(preorder[0] == \'#\' and preorder.size() != 1)\n        return false;\n        int c = 1;\n        for(int i=0;i<preorder.size();i++){\n            c -= 1;\n\n            if(c < 0)\n            return false;\n\n            if(preorder[i] != \'#\')\n            c += 2;\n\n            i++;\n            while(i<preorder.size() and preorder[i] != \',\')\n            i++;\n        }\n        if(c == 0) \n        return true;\n        return false;\n    }\n};\n```
['String', 'Stack', 'Tree', 'Binary Tree', 'C++']