当前位置:网站首页>牛客-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);
}
}
边栏推荐
- 2022-06-23: given a nonnegative array, select any number to make the maximum cumulative sum a multiple of 7, and return the maximum cumulative sum. N is larger, to the 5th power of 10. From meituan. 3
- 机器学习——感知机及K近邻
- Error reading CSV (TSV) file
- Open Oracle server under Linux to allow remote connection
- 读取csv(tsv)文件出错
- 学习使用php对字符串中的特殊符号进行过滤的方法
- 记录一下MySql update会锁定哪些范围的数据
- 涂鸦智能携多款重磅智能照明解决方案,亮相2022美国国际照明展
- leetCode-223: 矩形面积
- Status of the thread pool
猜你喜欢

4.分类管理业务开发

CVPR 2022 Oral | 英伟达提出自适应token的高效视觉Transformer网络A-ViT,不重要的token可以提前停止计算

Cookie encryption 4 RPC method determines cookie encryption

微信小程序学习之 实现列表渲染和条件渲染.

使用swiper左右轮播切换时,Swiper Animate的动画失效,怎么解决?

JS singleton mode

SQL Server AVG function rounding

413 binary tree Foundation

SQL Sever关于like操作符(包括字段数据自动填充空格问题)

Basic operations on binary tree
随机推荐
引擎国产化适配&重构笔记
Wechat applet learning to achieve list rendering and conditional rendering
学习整理在php中使用KindEditor富文本编辑器
线程池的状态
Programming questions (continuously updated)
小程序 rich-text中图片点击放大与自适应大小问题
CVPR 2022 oral | NVIDIA proposes an efficient visual transformer network a-vit with adaptive token. The calculation of unimportant tokens can be stopped in advance
线程池的执行流程
上升的气泡canvas破碎动画js特效
学习使用php对字符串中的特殊符号进行过滤的方法
416 binary tree (first, middle and last order traversal iteration method)
leetCode-面试题 16.06: 最小差
Engine localization adaptation & Reconstruction notes
分布式 | 如何与 DBLE 进行“秘密通话”
Three ways to use applicationcontextinitializer
Queue queue
4.分类管理业务开发
Graffiti smart brings a variety of heavy smart lighting solutions to the 2022 American International Lighting Exhibition
使用swiper左右轮播切换时,Swiper Animate的动画失效,怎么解决?
Operator details