My 60ms Python solution


  • 0
    C
    if not root:
            return 0
        else:
            l = [[root]]
            while True:
                temp = []
                for node in l[-1]:
                    if not (node.left or node.right):
                        return len(l)
                    if node.left:
                        temp.append(node.left)
                    if node.right:    
                        temp.append(node.right)
                l.append(temp)

Log in to reply
 

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