First Thoughts:
My Solution:
class Solution {
public boolean canAttendMeetings(int[][] intervals) {
for (int i=0; i<intervals.length; i++) {
int start = intervals[i][0];
int end = intervals[i][1];
for (int j=i+1; j<intervals.length; j++) {
int startSub = intervals[j][0];
int endSub = intervals[j][1];
if (startSub > start && startSub < end ||
endSub > start && endSub < end ||
startSub > start && endSub <end ||
startSub <= start && endSub >= end) return false;
}
}
return true;
}
}
Improved Time Efficiency Solution:
public boolean canAttendMeetings(int[][] intervals) {
PriorityQueue<Integer> times = new PriorityQueue<>((a, b) => a.length()-b.length())
for (int[] t : intervals) times.add(t);
int[] top = times.poll();
while(!times.isEmpty()) {
int[] next = times.pop();
if (top[1] > next[0]) return false;
top = next;
}
return true;
}