mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
24 lines
549 B
C
24 lines
549 B
C
/**
|
|
* Definition for a binary tree node.
|
|
* struct TreeNode {
|
|
* int val;
|
|
* struct TreeNode *left;
|
|
* struct TreeNode *right;
|
|
* };
|
|
*/
|
|
|
|
bool checkSymmetric(struct TreeNode *left, struct TreeNode *right)
|
|
{
|
|
if (!left || !right)
|
|
return left == right;
|
|
if (left->val != right->val)
|
|
return 0;
|
|
return checkSymmetric(left->left, right->right) &&
|
|
checkSymmetric(left->right, right->left);
|
|
}
|
|
|
|
bool isSymmetric(struct TreeNode *root)
|
|
{
|
|
return root == NULL || checkSymmetric(root->left, root->right);
|
|
}
|