3 lines python solution by re
import re\n    class Solution(object):\n        def isValidSerialization(self, preorder):\n            while re.search('[0-9]+,#,#', preorder):\n               
    import re\n    class Solution(object):\n        def isValidSerialization(self, preorder):\n            while re.search('[0-9]+,#,#', preorder):\n                preorder = re.sub('[0-9]+,#,#', '#', preorder)\n            return preorder == '#'
[]