感觉二叉树用递归基本都能做出来,这个也比较简单
bool hasPathSum(TreeNode* root,int sum){
if(root==NULL)
return false;
TreeNode*l=root->left;
TreeNode*r=root->right;
if(l==NULL&&r==NULL&&root->val==sum)
return true;
else
return hasPathSum(l,sum-root->val)||hasPathSum(r,sum-root->val);
}