import java.util.*;
public class Solution {
public boolean hasPathSum (TreeNode root, int sum) {
// 预处理
if (root == null) return false;
// 当前结点为叶子结点
if (root.left == null && root.right == null && root.val == sum) {
return true;
}
// 递归进入子结点
return hasPathSum(root.left,sum-root.val) || hasPathSum(root.right,sum-root.val);
}
}



京公网安备 11010502036488号