Path Sum III
来源:互联网 发布:有道mac离线缓存 编辑:程序博客网 时间:2024/06/05 08:42
啊这个递归总是会加重或者少加,办法就是你写出来那个过程,就知道哪里重了哪里少加了........
/** * 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: int pathSum(TreeNode* root, int sum) { if(root==NULL) return 0; return pathThis(root,sum)+pathSum(root->left,sum)+pathSum(root->right,sum); } int pathThis(TreeNode* root,int sum){ if(root==NULL) return 0; int temp=0; if(root->val==sum) temp+=1; return temp+pathThis(root->left,sum-root->val)+ pathThis(root->right,sum-root->val); } };
0 0
- 437. Path Sum III
- 437. Path Sum III
- 437. Path Sum III
- Path Sum III
- 437. Path Sum III
- 437. Path Sum III
- Path Sum III
- 437. Path Sum III
- LeetCode-Path Sum III
- path sum iii-leetcode
- Path Sum III ---LeetCode
- Leetcode | Path Sum III
- 437. Path Sum III
- 437. Path Sum III
- LeetCode437. Path Sum III
- Leetcode Path Sum III
- 437. Path Sum III
- 437. Path Sum III*
- 在iOS新建cocos2d-x工程之后需要手动拖动resouce文件进入Xcode
- maven中如何打包源代码
- 小谈闭包
- 标准模板库STL
- follow Sam哥 OS 课程的漫长之路
- Path Sum III
- android直接拿来用的开源项目
- 百练_3670计算鞍点
- 常用来设置断点的API
- 3D多边形背景动画
- android launchmode(四种启动模式)应用场景及实例
- hashMap,treeMap,LinkedHashMap的默认排序
- Java实现表达式计算 蓝桥杯
- MongoDB学习