Python solution - 58 ms, beats 97.34%


  • 0
    P
    class Solution(object):
        def minDepth(self, root):
            """
            :type root: TreeNode
            :rtype: int
            """
            if not root:
                return 0
            queue = [root]
            height = 0
            while queue:
                # node = queue.pop(0)
                height += 1 
                ls = [] 
                for temp in queue:
                    if not temp.right and not temp.left:
                        return height 
                    if temp.left:
                        ls.append(temp.left)
                    if temp.right:
                        ls.append(temp.right)
                queue = ls 
            return height 
    

Log in to reply
 

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