-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path101 Symmetric Tree.c
More file actions
42 lines (36 loc) · 796 Bytes
/
Copy path101 Symmetric Tree.c
File metadata and controls
42 lines (36 loc) · 796 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
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
void symmetric(struct TreeNode * root1, struct TreeNode * root2, bool * flag)
{
if(!root1 && !root2)
return;
if( (root1 == NULL) && (root2!=NULL) )
{
*flag = false;
return;
}
if( (root2 == NULL) && (root1!=NULL))
{
*flag = false;
return;
}
if(root1->val != root2->val)
{
*flag = false;
return;
}
symmetric(root1->left, root2->right, flag);
symmetric(root1->right, root2->left, flag);
}
bool isSymmetric(struct TreeNode* root)
{
bool flag = true;
symmetric(root->left, root->right, &flag);
return flag;
}