bool is_same(struct TreeNode* root1, struct TreeNode* root2)
{
if (root1 == NULL && root2 == NULL)
{
return true;
}
else if (root1 != NULL && root2 != NULL)
{
if (root1->val != root2->val)
{
return false;
}
else
{
return is_same(root1->left, root2->right) && is_same(root1->right, root2->left);
}
}
else
{
return false;
}
}
bool isSymmetric(struct TreeNode* root)
{
if (root->left == NULL && root->right == NULL)
{
return true;
}
else
{
return is_same(root->left, root->right);
}
}
101. 对称二叉树
最新推荐文章于 2024-05-31 17:17:25 发布