1 Star 0 Fork 0

表情扭曲 / leetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc112.java 889 Bytes
一键复制 编辑 原始数据 按行查看 历史
liu13 提交于 2019-03-20 10:14 . 20190320
package code;
/*
* 112. Path Sum
* 题意:是否存在跟到叶子节点的和为sum
* 难度:Easy
* 分类:
* 思路:
* Tips:lc112, lc113, lc437, lc129, lc124, lc337
* 总结一下 lc112 找跟到叶子和为sum的路径是否存在
* lc113 把lc112的路径找出来
* lc437 是任意一条向下走的路径
* lc129 计算所有的和
* lc124 任意一条路径
* lc337 树的dp
*/
public class lc112 {
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) {
val = x;
}
}
public boolean hasPathSum(TreeNode root, int sum) {
if(root==null) return false;
if(root.val==sum&&root.left==null&&root.right==null) return true;
return hasPathSum(root.left, sum-root.val)||hasPathSum(root.right, sum-root.val);
}
}
1
https://gitee.com/abfantasy/leetcode.git
git@gitee.com:abfantasy/leetcode.git
abfantasy
leetcode
leetcode
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891