Error: illegal start of expression followed by PriorityQueue

Jackie Wang

I am doing leetcode practicing and have the following piece of code:

    PriorityQueue<int[]> q=new PriorityQueue<int[]>(new Comparator<int[]>(){
        public int compare(int[] o1, int[] o2){
            return o1[0]-o2[0];
        }
    });
    q.add([0,1]);
    q.add([1,1]);
    q.add([2,1]);

where I got

Line 10: error: illegal start of expression

I really wonder what's the problem of this code?

Alkis Mavridis

I guess the problem is in the way you try to create the int arrays.

In java you cannot use square braces like [1,2,3] to create arrays. Instead, try something like

q.add(new int[] {1,2});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Java Error: illegal start of expression

Compile Error: illegal start of expression

"Illegal start of expression" error in Java

Error in code, "illegal start of expression"

java illegal start of expression error

Error illegal start of simple expression

Receiving Illegal start of expression error

Illegal start of expression error in Java

Weird "illegal start of expression" error in Netbeans

error: illegal start of expression in Android Studio Code

javac strange syntax - error illegal start of expression

How to fix illegal start of expression compilation error?

Error code compiling: illegal start of expression

Illegal start of expression for Annotations

Why is this an illegal start of expression?

Illegal start of expression (method)

I keep getting an "illegal start of expression" error on my code

java error in for loop condition evaluation: not a statement, illegal start of expression

What's wrong with my java program, "illegal start of expression error"

Netbeans is giving me "illegal start of expression" error message on my methods

'Try without catch error', ')' expected, illegal start of expression..?

Running into an illegal start of expression error while changing the value of an array

error: illegal start of expression in my Android studio code

Illegal Start of Expression, trying to print

Why is it saying illegal start of expression?

Why is this an illegal start of expression?and not a statement?

error: illegal start of type

Netbeans "illegal start of type" error

JSP Error "Illegal start of type"