(TreeNode root, int sum)
| 15 | */ |
| 16 | class Solution { |
| 17 | public boolean hasPathSum(TreeNode root, int sum) { |
| 18 | if(root == null){ |
| 19 | // exception |
| 20 | return false; |
| 21 | } |
| 22 | if(root.left == null && root.right == null){ |
| 23 | if(sum == root.val){ |
| 24 | return true; |
| 25 | } |
| 26 | return false; |
| 27 | } |
| 28 | else{ |
| 29 | boolean left = false; |
| 30 | boolean right = false; |
| 31 | if(root.left != null){ |
| 32 | left = hasPathSum(root.left, sum-root.val); |
| 33 | } |
| 34 | if(root.right != null){ |
| 35 | right = hasPathSum(root.right, sum-root.val); |
| 36 | } |
| 37 | return left||right; |
| 38 | } |
| 39 | } |
| 40 | } |
nothing calls this directly
no outgoing calls
no test coverage detected