-
Notifications
You must be signed in to change notification settings - Fork 277
/
Copy pathMyCalendarI.java
31 lines (27 loc) · 895 Bytes
/
MyCalendarI.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class MyCalendar {
// FloorEntry => Lower Entry Value
// CeilingEntry => High Entry Value
TreeMap<Integer, Integer> calendar = null;
public MyCalendar() {
calendar = new TreeMap<>();
}
public boolean book(int start, int end) {
// Condition around start time
// start < Lower Entry End Time
if(calendar.floorEntry(start) !=null && start < calendar.floorEntry(start).getValue()){
return false;
}
// Condition around end
// end > Higher Entry Start Time
if(calendar.ceilingEntry(start) !=null && end> calendar.ceilingEntry(start).getKey()){
return false;
}
calendar.put(start, end);
return true;
}
}
/**
* Your MyCalendar object will be instantiated and called as such:
* MyCalendar obj = new MyCalendar();
* boolean param_1 = obj.book(start,end);
*/