文章目录
- 题目介绍
- 题解
题目介绍


题解
class Solution {
public boolean hasPathSum(TreeNode root, int targetSum) {
// 只在最开始的时候判断树是否为空
if (root == null) {
return false;
}
targetSum -= root.val;
if (root.left == null && root.right == null) { // root 是叶子节点
return targetSum == 0;
}
return hasPathSum(root.left, targetSum) || hasPathSum(root.right, targetSum);
}
}










![[Redis][集群][上]详细讲解](https://i-blog.csdnimg.cn/direct/596a5e439a544bab81d2161f7010cc69.png)








![[Linux] Linux操作系统 进程的优先级 环境变量(一)](https://i-blog.csdnimg.cn/direct/7b78d48182fc4735a04f1c824cbc2ac4.png)