题解
判断二叉树是否相等
http://www.nowcoder.com/questionTerminal/9a9e74b71f944efab9992925f7f9a65e
public class Solution { /** * * @param p TreeNode类 * @param q TreeNode类 * @return bool布尔型 */ public boolean isSameTree (TreeNode p, TreeNode q) { // 两棵树相等的条件是 根节点的值相同,同时左右子树也相同 if(p == null && q == null) return true; if(p == null || q == null) return false; if (p.val != q.val) return false; return isSameTree(p.left, q.left) && isSameTree(p.right, q.right); } }