LintCode 469-等价二叉树

来源:互联网 发布:下载word2010软件 编辑:程序博客网 时间:2024/05/18 00:43

本人电子系,只为一学生。心喜计算机,小编以怡情。


 public boolean isIdentical(TreeNode a, TreeNode b) {       // Write your code here       if(a!=null && b!=null){           boolean m=isIdentical(a.left,b.left);           boolean n=isIdentical(a.right,b.right);           //后序遍历           if(a.val!=b.val)//如果值不等,直接返回错               return false;           else//否则看看左右子树返回的是对是错               return m&&n;       }       else if(a!=null || b!=null){           return false;       }       else{           return true;       }   }