我的算法之路9--二叉树的最大深度

# 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: TreeNode) -> int:
        if not root:
            return 0
        ml=1+self.maxDepth(root.left)
        mr=1+self.maxDepth(root.right)
        return max(ml,mr)

猜你喜欢

转载自blog.csdn.net/joaming/article/details/89364402