leetcode Maximum Depth of Binary Tree python
2015-12-06 15:45
549 查看
# 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 Minimum Depth of Binary Tree python
- python解析json文件
- 【python】python中的多态与duck typing
- LDA(线性判别分析,Python实现)
- selenium python (九)对话框处理
- leetcode Binary Tree Level Order Traversal python
- Python爬虫实战一之爬取糗事百科段子
- Python/Django 生成二维码
- 零基础入门学习Python(2):字符串输出
- leetcode Invert Binary Tree python
- leetcode Binary Tree Paths python
- python struct中pack和unpack
- selenium python (八)定位frame中的对象
- python处理地理数据-geopandas和pyshp
- python:文本文件处理
- python
- python:时间处理模块
- 《利用python进行数据分析》读书笔记--第七章 数据规整化:清理、转换、合并、重塑(一)
- Head First Python Notes Chapter II 第二章
- python psutil 终止子进程