LeetCode
来源:互联网 发布:大数据是以hadoop 编辑:程序博客网 时间:2024/05/29 07:41
Q:
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
A:
# 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 """ if not root: return 0 leftDep = self.maxDepth(root.left) + 1 rightDep = self.maxDepth(root.right) + 1 return leftDep if leftDep >= rightDep else rightDep
阅读全文
0 0
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- leetCode
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode:
- leetcode
- 时间
- 【jzoj5346】【NOIP2017提高A组模拟9.5】【NYG的背包】【贪心】
- 聚类算法-dbscan算法的研究
- 深度学习(卷积神经网络)问题总结
- Node.js学习(1) 开发环境安装
- LeetCode
- 为什么每次开机第一次启动程序会很慢?
- select加线程的服务端代码
- bzoj1196[HNOI2006]公路修建问题
- Update an entity using spring data JPA
- 服务配置中心及负载均衡算法
- 逆序不重复的整数
- Android中有关数据库的知识总结
- ContentProvider和BroadcastReceiver