100. Same Tree
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.
Subscribe to see which companies asked this question
1.全局采用递归的方法
2.如何才相等?p=q=NULL
3.有3种情况不想等
(1)p!=NULL q==NULL;
(2)q!=NULL p==NULL
(3)p!=NULL q!=NULL p->val!=q->val (p q 不是叶子结点,而且值不相等)
具体的算法如下