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?
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.
Comments