Python BFS solution

  • 6
    class Solution(object):
        def maxDepth(self, root):
            :type root: TreeNode
            :rtype: int
            depth = 0
            level = [root] if root else []
            while level:
                depth += 1
                queue = []
                for el in level:
                    if el.left:
                    if el.right:
                level = queue
            return depth


Log in to reply

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