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.
解法1:递归 / 分治
经典的二叉树的问题,用递归很容易解决。两个树相等首先是root的值要一样,然后左子树相等,右子树相等。终结条件是如果值不一样或者有一个root为空另一个不是空则结构不同。
C++
|
|
Java1