-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path100_same_tree.c
More file actions
executable file
·51 lines (39 loc) · 822 Bytes
/
100_same_tree.c
File metadata and controls
executable file
·51 lines (39 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>
typedef _Bool bool;
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
};
bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
if (p == NULL) {
if (q == NULL) {
return 1;
} else {
return 0;
}
}
if (q == NULL) {
if(p != NULL) {
return 0;
}
}
if (p->val != q->val) {
return 0;
} else {
return 1 * isSameTree(p->left, q->left) * isSameTree(p->right, q->right);
}
}
int main() {
struct TreeNode *p, *q;
bool a;
p = NULL;
q = (struct TreeNode *)malloc(sizeof(struct TreeNode));
q->val = 0;
q->left = NULL;
q->right = NULL;
a = isSameTree(p, q);
printf("%d\n", a);
return 0;
}