# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def maxDepth(self, root):
"""
:type root: TreeNode
:rtype: int
"""
if root == None:
return 0
depth_l, depth_r = 0, 0
if root.left:
depth_l = self.maxDepth(root.left)
if root.right:
depth_r = self.maxDepth(root.right)
return max(depth_l, depth_r) + 1
Python, LeetCode, 104. 二叉树的最大深度
最新推荐文章于 2021-05-27 19:55:10 发布