Leetcode 113. 路径总和 II
2018-07-22 08:49
399 查看
/** * 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: vector<vector<int>> res; vector<int> aux; void pathSum1(TreeNode* root, int sum) { if(root->left == root->right) { if(sum == root->val) { aux.push_back(sum); res.push_back(aux); aux.pop_back(); } } aux.push_back(root->val); if(root->left) { pathSum1(root->left, sum-root->val); } if(root->right) { pathSum1(root->right, sum-root->val); } aux.pop_back(); } vector<vector<int>> pathSum(TreeNode* root, int sum) { res.clear(); if(root==NULL) return vector<vector<int>>(); pathSum1(root, sum); return res; } };
相关文章推荐
- [LeetCode]113. Path Sum II(列出二叉树根到叶路径和等于sum的所有路径)
- [LeetCode] 113. Path Sum II 路径和 II
- leetcode 113. Path Sum II (路径和) 解题思路和方法
- leetcode 113. Path Sum II-路径和|回溯算法
- leetcode 113. Path Sum II (路径和) 解题思路和方法
- LeetCode 113. Path Sum II(路径和)
- Leetcode 113. Path Sum II 路径和2 解题报告
- [Leetcode] unique paths ii 独特路径
- [LeetCode 112 113] - 路径和I & II (Path Sum I & II)
- [LeetCode]112. Path Sum&113. Path Sum II
- [LeetCode] 113. Path Sum II
- [LeetCode] Unique Paths II 起点与终点确定的路径数II
- Leetcode 40. 组合总和 II
- [leetcode] @python 113. Path Sum II
- [leetcode]113. Path Sum II -- JavaScript 代码
- Leetcode 113. Path Sum II (Medium) (cpp)
- Leetcode 113. Path Sum II
- Leetcode-113. Path Sum II
- LeetCode-113. Path Sum II
- [LeetCode] 113. Path Sum II