boolbook(int startTime, int endTime){ for (int i = 0; i < overlap_start.size(); i++) { if (endTime > overlap_start[i] && overlap_end[i] > startTime) { returnfalse; } } for (int i = 0; i < booked_start.size(); i++) { if (endTime > booked_start[i] && booked_end[i] > startTime) { overlap_start.push_back(max(startTime, booked_start[i])); overlap_end.push_back(min(endTime, booked_end[i])); } } booked_start.push_back(startTime); booked_end.push_back(endTime); returntrue; } };
/** * Your MyCalendarTwo object will be instantiated and called as such: * MyCalendarTwo* obj = new MyCalendarTwo(); * bool param_1 = obj->book(startTime,endTime); */
defbook(self, startTime: int, endTime: int) -> bool: ifany(endTime > s and e > startTime for s, e inself.overlap): returnFalse for s, e inself.booked: if endTime > s and e > startTime: self.overlap.append((max(startTime, s), min(endTime, e))) self.booked.append((startTime, endTime)) returnTrue
# Your MyCalendarTwo object will be instantiated and called as such: # obj = MyCalendarTwo() # param_1 = obj.book(startTime,endTime)
publicbooleanbook(int startTime, int endTime) { for (inti=0; i < overlap_start.size(); i++) { if (endTime > overlap_start.get(i) && overlap_end.get(i) > startTime) { returnfalse; } } for (inti=0; i < booked_start.size(); i++) { if (endTime > booked_start.get(i) && booked_end.get(i) > startTime) { overlap_start.add(Math.max(startTime, booked_start.get(i))); overlap_end.add(Math.min(endTime, booked_end.get(i))); } } booked_start.add(startTime); booked_end.add(endTime); returntrue; } }
/** * Your MyCalendarTwo object will be instantiated and called as such: * MyCalendarTwo obj = new MyCalendarTwo(); * boolean param_1 = obj.book(startTime,endTime); */