1、题目
https://leetcode-cn.com/problems/path-sum/
2、题意
题解1:递归 用sum-当前节点
当当前节点左右子数都为空 若sum-当前节点为0说明有解
class Solution {
public:
bool hasPathSum(TreeNode *root, int sum) {
if(!root) return false;
if(!root->left&!root->right) return sum==root->val;
return hasPathSum(root->left,sum-root->val)||hasPathSum(root->right,sum-root->val);
}
};