Python recursive solution


  • 0
    T
    # class TreeNode(object):
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    
    class Solution(object):
        def maxDepth(self, root):
            """
            :type root: TreeNode
            :rtype: int
            """
            if root==None:
            	return 0
            else:
            	left=self.maxDepth(root.left)
            	right=self.maxDepth(root.right)
            	return max(left+1,right+1)
    

Log in to reply
 

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