class Solution {
boolean res;
public boolean hasPathSum(TreeNode root, int targetSum) {
if(root==null)return false;
rootsum(root,targetSum);
return res;
}
public void rootsum(TreeNode root, int targetSum){
if(root==null)return;
if(root.val==targetSum&&(root.right==null&&root.left==null))res = true;
rootsum(root.left,targetSum-root.val);
rootsum(root.right,targetSum-root.val);
}
}