3 lines python solution by re


  • 4
    Z
    import re
    class Solution(object):
        def isValidSerialization(self, preorder):
            while re.search('[0-9]+,#,#', preorder):
                preorder = re.sub('[0-9]+,#,#', '#', preorder)
            return preorder == '#'

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.