题目链接:click~
/*题意:给出一颗树和一个值sum,求树中是否存在从根结点到叶子结点的一条路径
使得这条路径上结点的和等于sum */
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);
}
};