二叉树的最大深度
程序员文章站
2022-06-17 19:47:16
...
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def maxDepth(self, root):
if not root:
return 0
max_left = self.maxDepth(root.left)
max_right = self.maxDepth(root.right)
return max(max_left, max_right) + 1