-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path101.cpp
40 lines (33 loc) · 828 Bytes
/
101.cpp
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
// 101. Symmetric Tree - https://leetcode.com/problems/symmetric-tree
#include <bits/stdc++.h>
using namespace std;
// 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 helper(TreeNode* p, TreeNode* q) {
if (p && q) {
return p->val == q->val && helper(p->right, q->left) && helper(p->left, q->right);
} else if (!p && !q) {
return true;
} else {
return false;
}
}
bool isSymmetric(TreeNode* root) {
if (root) {
return helper(root->left, root->right);
} else {
return true;
}
}
};
int main() {
ios::sync_with_stdio(false);
return 0;
}