题解 | #判断二叉树是否相等#
判断二叉树是否相等
http://www.nowcoder.com/practice/9a9e74b71f944efab9992925f7f9a65e
判断走右子树是否对应相等
public class Solution { /** * * @param p TreeNode类 * @param q TreeNode类 * @return bool布尔型 */ public boolean isSameTree (TreeNode p, TreeNode q) { // write code here 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); } }