当前位置:网站首页>牛客-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);
}
}
边栏推荐
- 414-二叉树的递归遍历
- 美国电子烟巨头 Juul 遭遇灭顶之灾,所有产品强制下架
- Groovy obtains Jenkins credentials through withcredentials
- Internet of things? Come and see Arduino on the cloud
- Get the QR code of wechat applet with parameters - and share the source code of modifying the QR code logo
- Geogebra instance clock
- 百度网盘下载一直请求中问题解决
- 机器学习——感知机及K近邻
- Detailed explanation of PHP singleton mode
- 记录一下MySql update会锁定哪些范围的数据
猜你喜欢

Floating point notation (summarized from cs61c and CMU CSAPP)

Mise en œuvre du rendu de liste et du rendu conditionnel pour l'apprentissage des applets Wechat.

植物生长h5动画js特效

保健品一物一码防窜货营销软件开发

解决Deprecated: Methods with the same name as their class will not be constructors in报错方案

Record the range of data that MySQL update will lock

形状变化loader加载jsjs特效代码

Leetcode-498: diagonal traversal

leetCode-498: 對角線遍曆

SQL Server AVG函数取整问题
随机推荐
二叉樹第一部分
学习使用php实现无限极评论和无限极转二级评论解决方案
canvas无限扫描js特效代码
2.登陆退出功能开发
Binary tree part I
Role of message queuing
SVG+js拖拽滑块圆形进度条
El table Click to add row style
Observer mode
411 stack and queue (20. valid parentheses, 1047. delete all adjacent duplicates in the string, 150. inverse Polish expression evaluation, 239. sliding window maximum, 347. the first k high-frequency
简单的价格表样式代码
Development of anti fleeing marketing software for health products
解决微信小程序rich-text富文本标签内部图片宽高自适应的方法
H5网页如何在微信中自定义分享链接
Juul, the American e-cigarette giant, suffered a disaster, and all products were forced off the shelves
Symbol. Iterator iterator
Machine learning perceptron and k-nearest neighbor
Use of vim
Array seamless scrolling demo
Troubleshooting steps for Oracle pool connection request timeout