forked from lolosssss/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path100_same_tree.c
48 lines (44 loc) · 902 Bytes
/
100_same_tree.c
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
/**
* Description : Same Tree
* Given two binary trees, write a functio to check if they are
* equal or not.
* Author : Evan Lau
* Date : 2016/05/03
*/
#include <stdio.h>
#include <stdbool.h>
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
};
bool isSameTree(struct TreeNode* p, struct TreeNode* q)
{
if (p != NULL && q != NULL)
{
if (p->val == q->val)
{
if (isSameTree(p->left, q->left) == false)
{
return false;
}
if (isSameTree(p->right, q->right) == false)
{
return false;
}
}
else
{
return false;
}
}
else if (p == NULL && q == NULL)
{
return true;
}
else
{
return false;
}
return true;
}