My Calendar II LeetCode solution in Java

1
class MyCalendarTwo {
2
private List<int[]> bookings;
3
private List<int[]> doubleBookings;
4

5
public MyCalendarTwo() {
6
bookings = new ArrayList<>();
7
doubleBookings = new ArrayList<>();
8
}
9

10
public boolean book(int start, int end) {
11
for (int[] b : doubleBookings) {
12
// condition to check for the overlaping
13
if (start < b[1] && end > b[0]) return false;
14
}
15

16
for (int[] b : bookings) {
17
if (start < b[1] && end > b[0]) {
18
doubleBookings.add(new int[] {Math.max(start, b[0]), Math.min(end, b[1])});
19
}
20
}
21
bookings.add(new int[] {start, end});
22
return true;
23
}
24
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0