首页 > 其他 > 详细

Leetcode_Path Sum

时间:2015-02-08 21:53:03      阅读:297      评论:0      收藏:0      [点我收藏+]
递归实现即可
class Solution {
public:
    bool hasPathSum(TreeNode *root, int sum) {
		if(!root)
			return false;
		if(root->left ==nullptr&&root->right==nullptr&&root->val==sum)
			return true;
		return hasPathSum(root->left,sum-root->val)||hasPathSum(root->right,sum-root->val);
        
    }
};

Leetcode_Path Sum

原文:http://blog.csdn.net/yinqiaohua/article/details/43646913

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