当前位置:网站首页>牛客-TOP101-BM29
牛客-TOP101-BM29
2022-06-24 09:46:00 【一条吃猫的鱼】
核心思路:递归
import java.util.*;
public class Solution {
public boolean hasPathSum (TreeNode root, int sum) {
//空节点找不到路径
if(root == null)
return false;
//叶子节点,且路径和为sum
if(root.left == null && root.right == null && sum - root.val == 0)
return true;
//递归进入子节点
return hasPathSum(root.left, sum - root.val) || hasPathSum(root.right, sum - root.val);
}
}
边栏推荐
猜你喜欢

2021-08-17

TP5 using post to receive array data times variable type error: solution to array error

植物生长h5动画js特效

How to improve the efficiency of network infrastructure troubleshooting and bid farewell to data blackouts?

正规方程、、、

SQL Sever中的窗口函数row_number()rank()dense_rank()

p5.js千纸鹤动画背景js特效

百度网盘下载一直请求中问题解决

Using pandas to read SQL server data table

Geogebra instance clock
随机推荐
leetCode-498: 對角線遍曆
JS proxy mode
Geogebra instance clock
leetCode-1823: 找出游戏的获胜者
tf.errors
Floating point notation (summarized from cs61c and CMU CSAPP)
np.float32()
机器学习——主成分分析(PCA)
Producer / consumer model
学习使用php对字符串中的特殊符号进行过滤的方法
uniapp实现禁止video拖拽快进
使用swiper左右轮播切换时,Swiper Animate的动画失效,怎么解决?
How to improve the efficiency of network infrastructure troubleshooting and bid farewell to data blackouts?
形状变化loader加载jsjs特效代码
PHP uses recursive and non recursive methods to create multi-level folders
如何在一个页面上使用多个KindEditor编辑器并将值传递到服务器端
416-二叉树(前中后序遍历—迭代法)
Go language development environment setup +goland configuration under the latest Windows
Detailed explanation of PHP singleton mode
JS singleton mode