112 Path Sum
2015-11-14 20:39
274 查看
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: bool hasPathSum(TreeNode* root, int sum) { if(root==NULL) return false; if(root->left==NULL&&root->right==NULL&&root->val==sum) return true; return hasPathSum(root->left, sum - root->val)||hasPathSum(root->right, sum - root->val); } };
相关文章推荐
- 10010---JavaWeb基础--HttpServlet
- Linux下的GPT分区
- 225 Implement Stack using Queues
- 动态页面jsp转换为html静态的网页
- 今天来学习下美团推荐算法实践:机器学习重排序模型
- pip安装mysql-python报致命错误:my_config.h:没有那个文件或目录
- 多态
- 172 Factorial Trailing Zeroes
- 118 Pascal's Triangle
- 运行地址和加载地址
- 第126讲:Hadoop集群管理之Datanode目录元数据结构详解学习笔记
- Ubuntu上安装谷歌第二代机器学习系统TensorFlow
- 66 Plus One
- IOS iPhone 开发中的文件读写及数据存储(一)
- 198 House Robber
- 关于htm和html,shtm与shtml,dhtml,xhtml之间的定义与区别
- 黑马视频-子查询
- 信息安全系统设计基础第九章学习总结
- HDU 1677 Nested Dolls
- 26 Remove Duplicates from Sorted Array