leetcode_c++:树: Path Sum(112)
来源:互联网 发布:choice python接口 编辑:程序博客网 时间:2024/06/07 06:38
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.
For example:
Given the below binary tree and sum = 22,
5 / \ 4 8 / / \ 11 13 4 / \ \ 7 2 1
return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.
class Solution {public: bool hasPathSum(TreeNode *root, int sum) { if (root == NULL) return false; if (!root->left && !root->right) return sum == root->val; return hasPathSum(root->left, sum - root->val) || hasPathSum(root->right, sum - root->val); }};
0 0
- leetcode_c++:树: Path Sum(112)
- leetcode_c++:Minimum Path Sum (064)
- leetcode_c++:树:Binary Tree Maximum Path Sum(124)
- leetcode_c++:树: Path SumII(113)
- leetcode_c++:Combination Sum(039)
- leetcode_c++:栈:Simplify Path(071)
- 112:Path Sum【树】【DFS】
- LeetCode(112) Path Sum
- leetcode_c++:3Sum(015)
- leetcode_c++:4sum(016)
- leetcode_c++:2Sum (001)
- [112]. Path Sum,[113]. Path Sum II
- leetcode_c++:树:Sum Root to Leaf Numbers(129)
- LeetCode(112)Path Sum
- LeetCode 112 Path Sum
- LeetCode: Path Sum [112]
- LeetCode 112 Path Sum
- [leetcode 112] Path Sum
- 优秀blog
- 环境配置
- Linux文本过滤
- CoordinatorLayout
- Android应用程序四大组件分别是什么?各个组件所起到的作用是什么?
- leetcode_c++:树: Path Sum(112)
- css性能优化总结,工作中习惯css规范
- ios framework中使用了 Category 的时候,调用app出现 "selector not recognized"解决方法
- MyBatis学习总结(19)——Mybatis传多个参数(三种解决方案)
- 谈一谈今年的移动互联网寒冬
- 异或求校验和
- spring->动态代理
- Introduction to Algorithm 3rd Edition
- requests不容易注意到的细节收集~