leetcode Maximum Depth of Binary Tree python
# 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 root == None:
return 0
if root.left == None and root.right != None:
return self.maxDepth(root.right)+1
if root.left != None and root.right == None:
return self.maxDepth(root.left)+1
return max(self.maxDepth(root.left),self.maxDepth(root.right))+1
leetcode Maximum Depth of Binary Tree python的更多相关文章
- LeetCode——Maximum Depth of Binary Tree
LeetCode--Maximum Depth of Binary Tree Question Given a binary tree, find its maximum depth. The max ...
- [LeetCode] Maximum Depth of Binary Tree 二叉树的最大深度
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- Leetcode 104 Maximum Depth of Binary Tree python
题目: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the ...
- leetcode:Maximum Depth of Binary Tree【Python版】
# Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self ...
- Leetcode Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- [Leetcode] Maximum depth of binary tree二叉树的最大深度
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- [LeetCode] Maximum Depth of Binary Tree dfs,深度搜索
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- LeetCode Maximum Depth of Binary Tree (求树的深度)
题意:给一棵二叉树,求其深度. 思路:递归比较简洁,先求左子树深度,再求右子树深度,比较其结果,返回:max_one+1. /** * Definition for a binary tree nod ...
- leetcode Minimum Depth of Binary Tree python
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = ...
随机推荐
- Ror初学笔记
Ror正在以惊人的速度增长着,特别是在常常光顾JavaEye的时候发现Ror已经在国内有非常好的基础了,当然要凑个热闹尝尝鲜 咯. 眼下国内Ror的中文资料还是非常少的,到网上找找就仅仅有Eiffel ...
- Java内存泄漏分析与解决方案
Java内存泄漏是每个Java程序员都会遇到的问题,程序在本地运行一切正常,可是布署到远端就会出现内存无限制的增长,最后系统瘫痪,那么如何最快最好的检测程序的稳定性,防止系统崩盘,作者用自已的亲身经历 ...
- 【线段树】【3-21个人赛】【同样的problemB】
同一道题 http://blog.csdn.net/zy691357966/article/details/44680121 区间查询最大值 用线段树 比单调队列慢 #include <cst ...
- js 正则表达式验证 整理
1.验证首字符是英文字母: var str="123"; var reg=/^[a-zA-Z]/; if(!reg.test(str)){ alert(str+"应以字母 ...
- WampServer2.5的XDebug调试不成功的原因
WampServer2.5的php.ini文件位置很奇妙,除了在“wamp\bin\php\php5.5.12”目录下有一个外,“wamp\bin\apache\apache2.4.9\bin”目录下 ...
- PHP zip压缩文件及解压
PHP zip压缩文件及解压 利用ZipArchive 类实现 只有有函数.界面大家自己写 ZipArchive(PHP 5.3 + 已自带不需要安装dll) /** * 文件解压 * @param ...
- android Mvp简单实用
View 对应于Activity,负责View的绘制以及与用户交互Model 依然是业务逻辑和实体模型Presenter 负责完成View于Model间的交互 模拟客户端的登录操作,并实现登录成功与登 ...
- JQUERY选择和操作DOM元素(利用正则表达式的方法匹配字符串中的一部分)
JQUERY选择和操作DOM元素(利用正则表达式的方法匹配字符串中的一部分) 1.匹配属性的开头 $("[attributeName^='value']"); 2.匹配属性的结尾 ...
- RenderPartial: No overload for method 'Write' takes 0 arguments
如下方法调用RenderPartial: 报“No overload for method 'Write' takes 0 arguments”的错误: @if (@Model != null &am ...
- 查看Linux下网卡状态或 是否连接
分类: 1) 通过mii-tool指令 [root@localhost root]# mii-tool eth0: negotiated 100baseTx-FD, link ...