My 1ms java solution


  • 0
    D
    public boolean isSymmetric(TreeNode root) {
        if(root == null){
            return true;
        }
        return isLegal(root.left,root.right);
    }
    
    public boolean isLegal(TreeNode left,TreeNode right){
        if(left==null && right==null){
            return true;
        }else if(left!=null && right!=null){
            if(left.val != right.val)
                return false;
            boolean l= isLegal(left.left,right.right);
            boolean r=isLegal(left.right,right.left);
            return (l && r);
        }
        return false;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.