50028. Subtrees
難度:4.25/5
Second Try: 4/5 Used Time: 15:20
I just can't think of it...1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include "subtree.h"
int n = 0;
int solve(Node* root, int k, int arr[]){
if(!root) return 0;
int l = solve(root->left, k, arr);
int r = solve(root->right, k, arr);
if((l) && (r) && (root->label != k)){
arr[n++] = root->label;
}
return (l) || (r) || (root->label == k);
}
int getNode(Node *root, int label[], int k){
n = 0;
int* arr = label;
solve(root, k, label);
return n;
}
50028. Subtrees
https://aaronlin1229.github.io/judgegirl_50028/