这道题主要考察利用画图解决抽象问题。
具体分析参考剑指offer28.
时间和内存消耗以及源代码如下:
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
bool isAssymetric(struct TreeNode* pRight, struct TreeNode* pLeft)
{
if (pRight == NULL && pLeft == NULL)
{
return true;
}
if (pRight == NULL || pLeft == NULL)
{
return false;
}
if (pRight->val != pLeft->val)
{
return false;
}
return isAssymetric(pRight->right, pLeft->left)
&& isAssymetric(pRight->left, pLeft->right);
}
bool isSymmetric(struct TreeNode* root){
if (root == NULL)
{
return true;
}
return isAssymetric(root->left, root->right);
}