Python3 Easy to understand
\nWe can keep trimming the leaves until there is no one to remove. If a sequence is like "9 # #", change it to "#" and continue. \n\nclass Solution:\n    def is
![image](https://assets.leetcode.com/users/jingdamai/image_1557994553.png)\nWe can keep trimming the leaves until there is no one to remove. If a sequence is like "9 # #", change it to "#" and continue. \n```\nclass Solution:\n    def isValidSerialization(self, preorder: str) -> bool:\n        tree = preorder.split(\',\')\n        stack = []\n        \n        for node in tree:\n            if not stack or node != \'#\':\n                stack.append(node)\n            else:\n                while stack and stack[-1] == \'#\':\n                    stack.pop()\n                    if not stack:\n                        return False\n                    else:\n                        stack.pop()\n                stack.append(\'#\')\n        \n        return len(stack) == 1 and stack[-1] == \'#\'\n```
[]