```
enter code here
```

public class Solution {

```
public boolean check = false ;
public boolean hasPathSum(TreeNode root, int sum) {
int val = 0 ;
if(root == null ) {return false ;}
if(root.left == null && root.right == null){
if(root.val == sum){return true ;}
}
hasPathSumVal(root,sum,val);
return check ;
}
public void hasPathSumVal(TreeNode root, int sum ,int val) {
if(root == null){if(sum==val){check = true;} return;}
val = val+root.val;
hasPathSumVal(root.left,sum,val);
hasPathSumVal(root.right,sum,val);
}
```