-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path101.cpp
More file actions
28 lines (25 loc) · 687 Bytes
/
101.cpp
File metadata and controls
28 lines (25 loc) · 687 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
/**
* 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) return true;
TreeNode *nd1 = root->left,*nd2 = root->right;
return equalNode(nd1,nd2);
}
private:
bool equalNode(TreeNode* nd1,TreeNode* nd2){
if(!nd1) return !nd2;
if(!nd2) return false;
if(nd1->val == nd2->val)
return equalNode(nd1->left,nd2->right) && equalNode(nd1->right,nd2->left);
return false;
}
};