Just the code : ))
\n\n# Code\n\nclass Solution:\n    def isValidSerialization(self, preorder: str) -> bool:\n        preorder = preorder.split(\',\')\n        stack = []\n       
\n\n# Code\n```\nclass Solution:\n    def isValidSerialization(self, preorder: str) -> bool:\n        preorder = preorder.split(\',\')\n        stack = []\n        node, left, right, cur = preorder[0], None, None, \'L\'\n        n = len(preorder)\n        if n == 1:\n            return node == \'#\'\n        elif node == \'#\':\n            return False\n\n        for i in range(1, n):\n            if preorder[i] == \'#\':\n                if cur == \'L\':\n                    cur = \'R\'\n                    left = \'#\'\n                else:\n                    if stack:\n                        node = stack.pop()\n                        left = "#"\n                        cur = \'R\'\n                    else:\n                        return i == n - 1\n            else:\n                stack.append(node)\n                node, left, right = preorder[i], None, None\n\n        return stack == [] and left == \'#\' and right == \'#\'\n```
['Python3']