# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = Noneclass Solution:
def maxDepth(self, root):
"""
:type root: TreeNode
:rtype: int
"""
#递归
if root is None:
return 0
left_height = self.maxDepth(root.left)
right_height = self.maxDepth(root.right)
return max(left_height,right_height)+1
leetcode - 104 - 二叉树的最大深度
最新推荐文章于 2021-05-21 03:59:10 发布