-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path894.cpp
More file actions
23 lines (23 loc) · 663 Bytes
/
Copy path894.cpp
File metadata and controls
23 lines (23 loc) · 663 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public:
vector<TreeNode *> allPossibleFBT(int N) {
if (N % 2 == 0 || N < 0)
return {};
else if (N == 1)
return {new TreeNode(0)};
vector<TreeNode *> ret;
for (int i = 1; i < N; i += 2) {
auto left = allPossibleFBT(N - i - 1);
auto right = allPossibleFBT(i);
for (auto &l:left) {
for (auto &r:right) {
auto node = new TreeNode(0);
node->left = l;
node->right = r;
ret.push_back(node);
}
}
}
return ret;
}
};