1class Solution {2public boolean hasPathSum(TreeNode root, int targetSum) {3if (root == null) return false;45if (root.left == null && root.right == null) return root.val == targetSum;67return hasPathSum(root.right, targetSum - root.val)8|| hasPathSum(root.left, targetSum - root.val);9}10}