| 1 | class MyCalendar { |
| 2 | TreeMap<Integer,Integer> map; |
| 3 | public MyCalendar() { |
| 4 | map = new TreeMap<>(); |
| 5 | } |
| 6 | |
| 7 | public boolean book(int start, int end) { |
| 8 | Integer prevVal = map.lowerKey(end); |
| 9 | if(prevVal!=null && start <= map.get(prevVal)-1){ |
| 10 | return false; |
| 11 | } |
| 12 | map.put(start,end); |
| 13 | return true; |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Your MyCalendar object will be instantiated and called as such: |
nothing calls this directly
no outgoing calls
no test coverage detected