在本篇文章中,我们主要介绍functionclass的内容,自我感觉有个不错的建议和大家分享下
每日一道理
只有启程,才会到达理想和目的地,只有拼搏,才会获得辉煌的成功,只有播种,才会有收获。只有追求,才会品味堂堂正正的人。
只有启程,才会到达理想和目的地,只有拼搏,才会获得辉煌的成功,只有播种,才会有收获。只有追求,才会品味堂堂正正的人。
struct TreeNode {int val;TreeNode *left;TreeNode *right;TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};class Solution {
//record all the path, though dfs is not time efficient bu also work at most time
public:void DFS(TreeNode* root, int curSum, vector<int> curPath, vector<vector<int>>& ansPath, int sum){if(!root)return;curSum += root->val;curPath.push_back(root->val);if(!root->left && !root->right){if(curSum == sum)ansPath.push_back(curPath);return;}DFS(root->left, curSum, curPath, ansPath, sum);DFS(root->right, curSum, curPath, ansPath, sum);}vector<vector<int> > pathSum(TreeNode *root, int sum) {// Start typing your C/C++ solution below// DO NOT write int main() functionvector<vector<int> > ansPath;vector<int> curPath;DFS(root, 0, curPath, ansPath, sum);return ansPath;}
};
文章结束给大家分享下程序员的一些笑话语录: 手机终究会变成PC,所以ip会比wm更加畅销,但是有一天手机强大到一定程度了就会发现只有wm的支持才能完美享受。就好比树和草,草长得再高也是草,时间到了条件成熟了树就会窜天高了。www.ishuo.cn
--------------------------------- 原创文章 By
function和class
---------------------------------