1. new Comparator<T>(){ public int compare(...) {}}, is a Comparator object so the () is needed;
  2. Collections.sort():
    1
    Line 3: error: no suitable method found for sort(int[][],<anonymous Comparator<int[]>>) Collections.sort(intervals, new Comparator<int[]>(){ ^ method Collections.<T#1>sort(List<T#1>) is not applicable (cannot infer type-variable(s) T#1 (actual and formal argument lists differ in length)) method Collections.<T#2>sort(List<T#2>,Comparator<? super T#2>) is not applicable (cannot infer type-variable(s) T#2 (argument mismatch; int[][] cannot be converted to List<T#2>)) where T#1,T#2 are type-variables: T#1 extends Comparable<? super T#1> declared in method <T#1>sort(List<T#1>) T#2 extends Object declared in method <T#2>sort(List<T#2>,Comparator<? super T#2>)

Collections.sort()底层用的就是Arrays.sort(), 两者底层都用的TimSort.sort();(见source code)

1
2
3
4
5
6
7
8
9
10
11
12
public boolean canAttendMeetings(int[][] intervals) {
s.sort(intervals, new Comparator<int[]>(){
public int compare(int[] i1, int[] i2) {
return (i1[0] - i2[0]);
}
});
for (int i = 0; i < intervals.length - 1; ++i) {
if (intervals[i][1] > intervals[i+1][0]) return false;
}
return true;
}
}