https://leetcode-cn.com/problems/path-sum/comments/
思路来自:用户mikiyashiki
public static boolean hasPathSum(TreeNode root, int sum) {
if(root==null) return false;
if(root.val==sum && root.left==null && root.right==null) return true;
return hasPathSum(root.right, sum - root.val) || hasPathSum(root.left, sum - root.val);
}