Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
一般树的问题,用递归方式比较容易解决:
if(p==NULL && q==NULL) return true;
else if(p==NULL) return false;
else if(q==NULL) return false;
return (p->val==q->val &&isSameTree(p->left,q->left)&& isSameTree(p->right,q->right));
尝试用了非递归算法,自己vs里创建两棵树比较,返回正确。这里一直报错。