blob: a1dad6f763836e7771c48ac4cb0f4f05b6e682af (
plain)
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
43
|
#include <cstddef>
struct TreeNode
{
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution
{
public:
static bool check(TreeNode *left, TreeNode *right)
{
if (left == NULL)
{
if (right == NULL)
return true;
else
return false;
}
else
{
if (right == NULL)
return false;
else
{
if (left->val != right->val)
return false;
return check(left->left, right->right) && check(left->right, right->left);
}
}
}
bool isSymmetric(TreeNode *root)
{
if (root == nullptr)
return true;
return check(root->left, root->right);
}
};
|