LeetCode 101 题解

深入理解 JVM 原理
深入理解 JVM 原理
wangxiaoming

已经通过

public class LeetCode101 {
    
    public boolean isSymmetric(TreeNode root) {
        if(root == null) return true;
        return isSyme(root.left,root.right);
    }

    /**
     * @param left
     * @param right
     * @return 
     */
    private boolean isSyme(TreeNode left, TreeNode right) {
        if(left == null && right == null) return true;
        if(left !=null && right != null && isEqual(left,right) && isEqual(left.left,right.right) && isEqual(left.right,right.left)){
            return isSyme(left.left,right.right) && isSyme(left.right, right.left);
        }else{
            return false;
        }
    }
    private boolean isEqual(TreeNode node1,TreeNode node2){
        if(node1 == null && node2 == null) return true;
        if(node1 != null && node2 != null && node1.val == node2.val) return true;
        return false;
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        
/*       1
        / \
       2   2
      / \ / \
     3  4 4  3*/
        
        /*TreeNode node1 =  new TreeNode(1);
        TreeNode node2 =  new TreeNode(2);
        TreeNode node3 =  new TreeNode(2);
        TreeNode node5 =  new TreeNode(3);
        TreeNode node6 =  new TreeNode(4);
        TreeNode node7 =  new TreeNode(4);
        TreeNode node8 =  new TreeNode(3);
        node1.left = node2;
        node1.right = node3;
        node2.left = node5;
        node2.right = node6;
        node3.left = node7;
        node3.right = node8;*/
        
        TreeNode node1 =  new TreeNode(1);
        TreeNode node2 =  new TreeNode(2);
        TreeNode node3 =  new TreeNode(3);
        node1.left = node2;
        node1.right = node3;
        System.out.println(new  LeetCode101().isSymmetric(node1));
    }

}

展开阅读全文
©️2020 CSDN 皮肤主题: Age of Ai 设计师: meimeiellie 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值