leetcode之Maximum Depth of Binary Tree

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

# 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
        """
        depth = 0
        if root == None:
            return 0
        else:        
            return 1 + depth + max(self.maxDepth(root.right), self.maxDepth(root.left))


阅读更多
上一篇leetcode之Basic Calculator II
下一篇leetcode之Implement Trie (Prefix Tree)
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭