leetcode - Path Sum II
2013-11-06 10:19
351 查看
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: void getResult (TreeNode * node, vector<vector<int>> & rlt, int target, vector<int> & curPath){ target -= node->val; vector<int> path = curPath; path.push_back(node->val); if (node->left==NULL && node->right==NULL && target==0){ rlt.push_back(path); return; } if (node->left!=NULL) getResult(node->left, rlt, target, path); if (node->right!=NULL) getResult(node->right, rlt, target, path); return; } vector<vector<int> > pathSum(TreeNode *root, int sum) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. vector<vector<int> > rlt; if (root==NULL) return rlt; vector<int> path; getResult(root, rlt, sum, path); return rlt; } };
相关文章推荐
- LeetCode:Path Sum II
- [LeetCode] Path Sum II
- 【LeetCode】Path Sum II
- LeetCode 113: Path Sum II
- LeetCode - Path Sum II
- [LeetCode] Path Sum II
- leetcode113. Path Sum II
- 【LeetCode】Path Sum II
- leetcode: Path Sum II
- [LeetCode] Path Sum II 解题报告
- LeetCode | Unique Paths & II & Minimum Path Sum
- LeetCode[Tree]: Path Sum II
- Leetcode--Path Sum II
- leetcode---path-sum-ii---树
- LeetCode Path Sum II
- 【LeetCode】Path Sum II
- leetcode -- Path Sum II --- 重点,未理解
- leetcode:Path Sum II (路径之和,记录结果路径)【面试算法题】
- LeetCode *** 113. Path Sum II
- LeetCode_Path Sum II