```
public class Solution {
public boolean hasPathSum(TreeNode root, int target) {
int sum = 0;
return hasPathSum(root,target,sum);
}
public boolean hasPathSum(TreeNode root, int target, int sum){
if(root==null) return false;
sum +=root.val;
if(root.left==null && root.right==null && sum == target) return true;
return hasPathSum(root.left, target, sum) || hasPathSum(root.right, target, sum);
}
}
```