leetcode之Maximum Depth of Binary Tree

来源:互联网 发布:口技box速成软件 编辑:程序博客网 时间:2024/06/05 05:08

基础的2叉树题。代码如下:

# Definition for a binary tree node.# class TreeNode(object):#     def __init__(self, x):#         self.val = x#         self.left = None#         self.right = Noneclass Solution(object):    def maxDepth(self, root):        """        :type root: TreeNode        :rtype: int        """        depth = 0        if root == None:            return 0        else:                    return 1 + depth + max(self.maxDepth(root.right), self.maxDepth(root.left))


0 0
原创粉丝点击