113. Path Sum II
来源:互联网 发布:1到n的阶乘的和的算法 编辑:程序博客网 时间:2024/05/23 02:25
//树中可能有正数负数,所以无法剪支,开始剪支了结果导致元素出现负的时候出错/** * 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: void get_path(vector<vector<int>> &v,vector<int> &temp,TreeNode* root,int a) { if(root->val==a&&!root->left&&!root->right) { temp.push_back(root->val); v.push_back(temp); temp.pop_back(); return; } temp.push_back(root->val); if(root->left) get_path(v,temp,root->left,a-root->val); if(root->right) get_path(v,temp,root->right,a-root->val); temp.pop_back(); } vector<vector<int>> pathSum(TreeNode* root, int sum) { if(!root) return {}; vector<vector<int>> v; vector<int> temp; get_path(v,temp,root,sum); return v; }};
0 0
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 分田
- hibernate4 映射集合属性 set
- 无线测试定义
- android 常用io操作总结
- HTTP协议详解
- 113. Path Sum II
- C++抽象类
- 【转载】Java中Runnable和Thread的区别
- Linux驱动开发-12、总线设备驱动模型
- Distributing Ballot Boxes(HDU1490)
- 引用
- shell 与 /etc/shells 功能
- Javassist学习总结
- J2EE轻量级框架--4.04学习心得