Tweaked Identical Binary Tree

Tweaked Identical Binary Tree

public class Solution{
  public boolean isTweakedIdentical(TreeNode a, TreeNode b){
    if(a == null && b == null) return true;
    
    if(a == null || b == null) return false;
    
    if(a.val != b.val) return false;
    
    return isTweakedIdentical(a.left, b.left) && isTweakedIdentical(a.right , b,right) || 
      isTweakedIdentical(a.left, b.right) && isTweakedIdentical(a.right , b.left);
  }
}

 

    1             1
   / \           / \
  2   3   and   3   2
 /                   \
4                     4

是扭转后可等价的二叉树。

    1             1
   / \           / \
  2   3   and   3   2
 /             /
4             4


作者:Jason_Yuan
链接:https://www.jianshu.com/p/0623cf8ad71b
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

 

posted on 2018-08-28 20:08  猪猪🐷  阅读(87)  评论(0)    收藏  举报

导航