Python Solution non-recursive version


  • 0
    K
    class Solution(object):
        def minDepth(self, root):
            if not root:
                return 0
            depth, level =1, [root]
            while level :
                netLevel=[]
                for n in level :
                    if  not n.left and not n.right :
                        return depth
                    if n.left:
                        netLevel.append(n.left)
                    if n.right:
                        netLevel.append(n.right)
                depth+=1
                level = netLevel
    
    

Log in to reply
 

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