Path Sum
2016-05-27 18:47
148 查看
# Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: # @param root, a tree node # @param sum, an integer # @return a boolean def hasPathSum(self, root, sum): ret = False if root == None: return ret sum -= root.val if sum==0 and root.left==None and root.right==None: ret = True return ret or self.hasPathSum(root.left,sum) or self.hasPathSum(root.right,sum)
相关文章推荐
- [原创]java WEB学习笔记24:MVC案例完整实践(part 5)---删除操作的设计与实现
- Python 学习之路——1
- 享元模式及php实现
- Python之self
- Python之self
- 《构建之法》第8、9、10章的读后感和第一个sprint总结
- 0527Sprint总结,读书笔记与提问
- Xcode多种Build Configuration配置使用
- JSONP伪同步请求及如何使用GBK 进行encodeURIComponet 编码
- OpenGL ES之GLSurfaceView学习一:介绍
- jar 程序发布脚本
- Codeforces Round #352 (Div. 2) C. Recycling Bottles
- 终端改变host的类型,还原
- 热加载
- Web前端学习第十二天·fighting_使用CSS布局和定位(二)
- DbUnit入门实战
- 分享一个mac自带小工具
- 逆波兰算法
- Linux---ubuntu重启网络服务
- python_爬取博客内容