-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP101.cpp
More file actions
26 lines (24 loc) · 695 Bytes
/
P101.cpp
File metadata and controls
26 lines (24 loc) · 695 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
#include "header.h"
class Solution {
public:
bool isSymmetric(TreeNode* root) {
if (!root) return true;
return isSymmetric(root->left, root->right);
}
bool isSymmetric(TreeNode* p, TreeNode* q) {
if (p && q)
if (p->val == q->val)
return isSymmetric(p->left , q->right) && isSymmetric(p->right , q->left);
else
return false;
else
if (!p && !q)
return true;
return false;
}
};
int main() {
TreeNode* root=NULL;
cout << Solution().isSymmetric(root);
return 0;
}