public boolean canAttendMeetings(Interval[] intervals) {
boolean[] timeLine = new boolean[1000000];// It should be a large integer based on ranges.
for(Interval interval: intervals) {
for(int i = interval.start; i< interval.end; i++) {
if(timeLine[i] == true)
return false;
timeLine[i] = true;
}
}
return true;
}
Java O(n) time and O(1) space using bit manipulation


Good idea. In case we may get overflow, we can use set instead!
Update:
LTE and MTE, damn!public boolean canAttendMeetings(Interval[] intervals) { HashSet<Integer> hs = new HashSet<Integer>(); for(Interval temp : intervals){ for(int i = temp.start; i < temp.end; i++){ if(hs.contains(i)) return false; hs.add(i); } } return true; }
