Easy to Understand Python code(recursive + beat 90%)


  • 0

    '''
    class Solution(object):
    def maxDepth(self, root):

        length = 0
        
        if root == None:
            return 0
        
        def isroot(root,length):
            if (root.right == None and root.left == None):
                length += 1
                return length
            else:
                length +=1
                if root.left == None:
                    return isroot(root.right,length)
                if root.right == None:
                    return isroot(root.left,length)
                return max(isroot(root.left,length),isroot(root.right,length))
                
        return isroot(root,length)
    

    '''
    DFS


Log in to reply
 

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