C/C++教程

leetcode101_对称二叉树

本文主要是介绍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;
    }
}
这篇关于leetcode101_对称二叉树的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!