98% iterative python solution


  • 0
    S
    d = 0
            if root == None:
                return d
            sq = [root]
            while sq:
                temp = []
                d += 1
                for i in sq:
                    if i.left or i.right:
                        if i.left != None:
                            temp.append(i.left)
                        if i.right != None:
                            temp.append(i.right)
                    else:
                        return d
                sq = temp
    

Log in to reply
 

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