题目
给出一个二叉树,找到它的最大深度。最大深度指的是根节点到最远叶节点的路径的长度。
Python题解
class Solution(object):
def maxDepth(self, root):
"""
:type root: TreeNode
:rtype: int
"""
if root is None:
return 0
left_depth = self.maxDepth(root.left)
right_depth = self.maxDepth(root.right)
return max(left_depth, right_depth) + 1