美文网首页
01_二叉树的最大深度

01_二叉树的最大深度

作者: butters001 | 来源:发表于2019-11-12 10:48 被阅读0次
# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
    def maxDepth(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
        if not root:
            return 0
        l = 1 + self.maxDepth(root.left)
        r = 1 + self.maxDepth(root.right)
        return max(l, r)

相关文章

网友评论

      本文标题:01_二叉树的最大深度

      本文链接:https://www.haomeiwen.com/subject/ahufictx.html