seven lines easy understanding python solution 91% defeat


  • 0
    W
    class Solution(object):
        def isValidSerialization(self, preorder):
            """
            :type preorder: str
            :rtype: bool
            """
            num,pre,i,a=preorder.split(','),0,0,1
            while a:
                i+=a
                if len(num[pre:i])!=a:
                    return False
                a,pre=len([b for b in num[pre:i] if b!='#'])*2,i
            return len(num)==i
    

Log in to reply
 

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