Path Sum ---LeetCode
来源:互联网 发布:淘宝装修自定义区全屏 编辑:程序博客网 时间:2024/05/07 11:17
https://leetcode.com/problems/path-sum/
解题思路:
这道题我们通过递归,依次将 sum 的值缩减,最终判断叶子节点是否等于 sum。
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public boolean hasPathSum(TreeNode root, int sum) { if (root == null) return false; if (root.left == null && root.right == null) return sum == root.val; return hasPathSum(root.left, sum - root.val) || hasPathSum(root.right, sum - root.val); }}
0 0
- leetcode Path Sum && Path Sum ||
- 【Leetcode】Path Sum (Sum)
- leetcode:leetcode :Path Sum
- 【Leetcode】Path Sum II (Sum)
- LeetCode: Minimum Path Sum
- LeetCode: Path Sum
- LeetCode: Path Sum II
- LeetCode Minimum Path Sum
- LeetCode Path Sum
- LeetCode Path Sum II
- [Leetcode] Path Sum
- [Leetcode] Path Sum II
- LeetCode : Minimum Path Sum
- [Leetcode] Minimum Path Sum
- LeetCode: Path Sum
- LeetCode: Path Sum II
- [LeetCode] Path Sum
- [LeetCode] Path Sum II
- 润乾报表自定义函数中获得类似A1:D1参数的值
- time函数的使用-测试程序用时
- HTML转PDF问题
- Git最佳实践与总结
- 批量修改Makefile内容
- Path Sum ---LeetCode
- Codeforces Round #382 (Div. 2)D. Taxes(数论知识)
- Effective Objective-C 2.0 Tips 总结 Chapter 1 & Chapter 2
- 解决maven工程中使用spring-boot后导致的profile多环境配置失效的问题
- Doxygen-程序文档工具
- Linux 进程管理
- selenuim +python环境配置遇到的诸多问题
- mysql引擎-锁-事务
- Android Studio目录结构浅析