首页 > 其他 > 详细

112. Path Sum

时间:2016-06-12 07:05:04      阅读:192      评论:0      收藏:0      [点我收藏+]

没啥要说的

 1     public boolean hasPathSum(TreeNode root, int sum) {
 2         if(root == null) {
 3             return false;
 4         }
 5         return helper(root, sum, 0);
 6     }
 7     
 8     private boolean helper(TreeNode root, int sum, int curSum) {
 9         if(root == null) {
10             return false;
11         }
12         if(root.left == null && root.right == null) {
13             return (curSum + root.val) == sum;
14         }
15         return helper(root.left, sum, curSum + root.val) || helper(root.right, sum, curSum + root.val);
16     }

 

112. Path Sum

原文:http://www.cnblogs.com/warmland/p/5576381.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!