functionclass[LeetCode]Path Sum II
生活随笔
收集整理的這篇文章主要介紹了
functionclass[LeetCode]Path Sum II
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在本篇文章中,我們主要介紹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
---------------------------------
轉載于:https://www.cnblogs.com/jiangu66/archive/2013/05/31/3111532.html
總結
以上是生活随笔為你收集整理的functionclass[LeetCode]Path Sum II的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 进程的创建与可执行程序的加载
- 下一篇: hdu 2444(二分图的判断以及求最大