面试题28:对称二叉树

2018-12-27  本文已影响0人  灰化肥发黑会挥发

判断一颗二叉树是不是对称二叉树

import javax.swing.tree.TreeNode;

public class isSymmetrical {
    public boolean judgeSymmetrical(TreeNode root){
        if(root==null) return true;
        return isSizeSummetrical(root,root);
    }
    public boolean isSizeSummetrical(TreeNode left,TreeNode right){
        if(left==null&&right==null) return true;
        if(left==null||right==null) return false;
        if(left.val!=right=val) return false;
        else 
            return  isSizeSummetrical(left.left,right.right)&&isSizeSummetrical(left.right,right,left);
    }
}
上一篇下一篇

猜你喜欢

热点阅读