public static boolean hasPathSum(BinTreeNode root, int sum) {
if(root == null) return false;
if(root.left == null && root.right == null && sum - root.value == 0) return true;
return hasPathSum(root.left, sum - root.value) || hasPathSum(root.right, sum - root.value);
}
网友评论