My Easy Python Solution (BFS,Beats 96.8%)


  • 0
    X
        def minDepth(self, root):
            if(not root):
                return 0
            queue = [root]
            level = 1
            while(queue):
                count = len(queue)
                for i in range(0, count):
                    node = queue.pop(0)
                    if(not node.left and not node.right):
                        return level
                    if(node.left):
                        queue.append(node.left)
                    if(node.right):
                        queue.append(node.right)
                level += 1

Log in to reply
 

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