LeetCode:Path Sum
来源:互联网 发布:虚空假面 jb脸 知乎 编辑:程序博客网 时间:2024/05/29 13:08
题目描述:
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.
bool Solution::hasPathSum(TreeNode *root, int sum){ if(root == NULL) return false; if(root->left == NULL && root->right == NULL) return root->val - sum; else 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
- non-transactional
- 初学unity3D
- java中的vo 、dto 、dao
- Apple list
- Hibernate的级联删除
- LeetCode:Path Sum
- 图片js切换
- CVS 常用操作命令
- Mac OX 10.10 cocoapods升级步骤
- 保存用户密码的安全方法 .
- eclipse自动提示补全功能
- Java 实现SM2 非对称加密、解密、签名、验签
- MyEclipse Servers 报错Could not create the view: An unexpected exception was thrown
- 快速批量替换文档中的回车符与换行符,包括分节符、分页符的替换