Accepted Solution in c++


#1

int Solution::isSameTree(TreeNode* A, TreeNode* B) {
if(A==NULL and B==NULL)
{
return 1;
}
if(A==NULL or B==NULL)
{
return 0;
}
if(A->val!=B->val) return 0;

int a = isSameTree(A->left,B->left);
free(A->left);//So that memory limit will not exceed
free(B->left);
int b = isSameTree(A->right,B->right);
free(A->right);
free(B->right);
return a and b; // return if a and b are equal
}