We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dc5adc7 commit a932f4dCopy full SHA for a932f4d
scripts/algorithms/M/My Calendar III/My Calendar III.java
@@ -1,29 +1,30 @@
1
+// Runtime: 197 ms (Top 36.54%) | Memory: 54.3 MB (Top 59.44%)
2
class MyCalendarThree {
3
4
TreeMap<Integer, Integer> map;
5
public MyCalendarThree() {
6
map = new TreeMap<>();
7
}
-
8
+
9
public int book(int start, int end) {
10
if(map.isEmpty()){
11
map.put(start, 1);
12
map.put(end,-1);
13
return 1;
14
15
- //upvote if you like the solution
16
+ //upvote if you like the solution
17
18
map.put(start, map.getOrDefault(start,0)+1);
19
map.put(end, map.getOrDefault(end,0)-1);
20
21
int res = 0;
22
int sum = 0;
23
for(Map.Entry<Integer, Integer> e: map.entrySet()){
24
sum += e.getValue();
25
res = Math.max(res,sum);
26
27
28
return res;
29
-}
30
+}
0 commit comments