请问自己写的代码错在哪里
题目:
C语言
我的代码:
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int calculation(struct TreeNode* t, int* a,int i)
{
if(t==NULL)
return i;
a[i++]=t->val;
calculation(t->left,a,i);
return calculation(t->right,a,i);
}
int calcu(struct TreeNode* t, int* a,int i)
{
if(t==NULL)
return i;
a[i++]=t->val;
calcu(t->right,a,i);
return calcu(t->left,a,i);
}
bool isSymmetric(struct TreeNode* root){
if(!root->left&&!root->right)
return true;
if(!root->left||!root->right)
return false;
int a1[1000]={0}, a2[1000]={0};
int count1=0, count2=0;
count1=calculation(root->left,a1,0);
count2=calcu(root->right,a2,0);
if(count1!=count2)
return false;
for(int i=0; i<count1; i++)
{
if(a1[i]!=a2[i])
return false;
}
return true;
}