C++
class Solution {
public:
bool static cmp(vector<int>& a,vector<int>& b){
if(a[0] != b[0]) return a[0] < b[0];
return a[1] < b[1];
}
bool canAttendMeetings(vector<vector<int>>& intervals) {
int r = intervals.size();
sort(intervals.begin(),intervals.end(),cmp);
for(int i = 0; i < r-1; i++){
if(intervals[i][1] > intervals[i+1][0]) return false;
}
return true;
}
};
JAVA
class Solution {
public boolean canAttendMeetings(int[][] intervals) {
int r = intervals.length;
Arrays.sort(intervals,new Comparator<int[]>(){
public int compare(int a[],int b[]){
if(a[0] != b[0]) return (a[0] - b[0]);
return (a[1] - b[1]);
}
});
for(int i = 0; i < r-1; i++){
if(intervals[i][1] > intervals[i+1][0]) return false;
}
return true;
};
}