-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path101.cpp
More file actions
29 lines (29 loc) · 724 Bytes
/
101.cpp
File metadata and controls
29 lines (29 loc) · 724 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
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution
{
public:
bool isSymmetric(TreeNode* root)
{
if(root==NULL)
return true;
return isSymmetric(root->left,root->right);
}
bool isSymmetric(TreeNode* left,TreeNode* right)
{
if(left==NULL && right==NULL)
return true;
if(left==NULL || right==NULL)
return false;
if(left->val!=right->val)
return false;
return (isSymmetric(left->left,right->right) && isSymmetric(left->right,right->left) );
}
};