leetcode Path Sum
来源:互联网 发布:淘宝订单体验 编辑:程序博客网 时间:2024/04/30 02:31
原题链接:https://leetcode.com/problems/path-sum/
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: bool hasPathSum(TreeNode* root, int sum) { return dfs(root, 0, sum); } bool dfs(TreeNode *x, int cur, int sum) { if (!x) return false; if (!x->left && !x->right) { if (sum == cur + x->val) return true; } if (dfs(x->left, cur + x->val, sum)) return true; if (dfs(x->right, cur + x->val, sum)) return true; return false; }};
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
- GDataXML 解析三方库
- Java对象循环引用,Java gc 如何回收
- shell脚本中生成的spool文件没有执行的语句
- POJ 1905 Expanding Rods几何题,二分
- nsq源码阅读笔记之nsqd(三)——diskQueue
- leetcode Path Sum
- Android中实现横屏竖屏的切换
- ubuntu linux下编辑更改镜像源
- USACO nocows
- python和php常用的时间处理
- JavaBean与JSON的转换
- Matlab的mapminmax函数说明
- Firemonkey实现iOS程序运行时更改锁定显示方向(LockOrientations)
- sap JCO3.0安装时遇到的问题