-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP113.cpp
More file actions
24 lines (21 loc) · 765 Bytes
/
P113.cpp
File metadata and controls
24 lines (21 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "header.h"
class Solution {
public:
vector<vector<int>> pathSum(TreeNode* root, int sum) {
if (!root) return {};
if (root->val == sum && !root->left && !root->right)
return {{root->val}};
vector<vector<int>> ret_c[2], ret_r, ret;
ret_c[0] = pathSum(root->left, sum - root->val);
ret_c[1] = pathSum(root->right, sum - root->val);
for (int i=0;i<2;i++)
for (auto t : ret_c[i]) {
vector<int> tmp = t;
if (!t.empty()) {
tmp.insert(tmp.begin(), root->val);
ret.push_back(tmp);
}
}
return ret;
}
};