leetcode101_对称二叉树

class Solution {
    public boolean isSymmetric(TreeNode root) {
        if(root == null) return true;
        return judge(root.left, root.right);
    }
    private boolean judge(TreeNode left, TreeNode right) {
        if(left == null && right == null) return true;
        else if(left != null && right != null && left.val != right.val) return false;
        else if(left != null && right == null) return false;
        else if(left == null && right != null) return false;

        boolean outside =  judge(left.left, right.right);
        boolean inside =  judge(left.right, right.left);
        return outside && inside;
    }
}
上一篇:6_66.加一


下一篇:【Java教程】Java 抽象工厂模式