leetcode 112 Path Sum
程序员文章站
2024-01-05 12:11:04
...
Java:
class Solution {
public boolean hasPathSum(TreeNode root, int sum) {
if (root == null ) return false;
if (root.left == null && root.right == null && sum-root.val ==0 ) return true;
sum = sum - root.val;
return hasPathSum(root.left, sum) || hasPathSum(root.right, sum);
}
}