#
# @lc app=leetcode.cn id=104 lang=python
#
# [104] 二叉树的最大深度
#
# @lc code=start
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution(object):
def maxDepth(self, root):
"""
:type root: TreeNode
:rtype: int
"""
if not root:return 0
l = self.maxDepth(root.left)
r = self.maxDepth(root.right)
return max(l, r) + 1
# @lc code=end
104.二叉树的最大深度
最新推荐文章于 2024-07-20 09:21:06 发布