leetcode之Maximum Depth of Binary Tree

原创 2015年11月20日 19:29:54

基础的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解题之Maximum/Minimum Depth of Binary Tree Java版(树的最大、最小深度)

leetcode解题之104# Maximum Depth of Binary Tree Java版(树的最大深度),111. Minimum Depth of Binary Tree(树的最大深度...

Leetcode-104. Maximum Depth of Binary Tree c语言

来源:104. Maximum Depth of Binary Tree 题目要求: Given a binary tree, find its maximum depth. The max...

LeetCode104 Maximum Depth of Binary Tree

详细见:leetcode.com/problems/maximum-depth-of-binary-tree Java Solution: github package leetcod...

开荒新系列之LeetCode: 002-Maximum Depth of Binary Tree

总结讨论在不看上一篇文章的前提下,回忆总结一下上次工作,看看到目前为止还记得多少: 要多手写一些测试数据 不止一种方法实现,寻找最简单的方法 python is 比 == 要快一点点 Maximum ...

LeetCode | Maximum Depth of Binary Tree

Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the l...

[LeetCode]104.Maximum Depth of Binary Tree

【题目】 Maximum Depth of Binary Tree  Total Accepted: 5260 Total Submissions: 11532My Submissions ...

LeetCode#104. Maximum Depth of Binary Tree

104. Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum dep...

【LeetCode】104. Maximum Depth of Binary Tree(DFS|BFS)

原题Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the lon...

Leetcode 104. Maximum Depth of Binary Tree (Easy) (cpp)

Leetcode 104. Maximum Depth of Binary Tree (Easy) (cpp)

<LeetCode OJ> (104 / 111) Maximum & Minimum Depth of Binary Tree

Maximum Depth of Binary Tree My Submissions Question Total Accepted: 107329 Total Submission...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)