1
class Solution {
2
public boolean hasPathSum(TreeNode root, int targetSum) {
3
if (root == null) return false;
4

5
if (root.left == null && root.right == null) return root.val == targetSum;
6

7
return hasPathSum(root.right, targetSum - root.val)
8
|| hasPathSum(root.left, targetSum - root.val);
9
}
10
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0