-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyCalendarThree.java
More file actions
45 lines (34 loc) · 1.09 KB
/
MyCalendarThree.java
File metadata and controls
45 lines (34 loc) · 1.09 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.TreeMap;
class MyCalendarThree
{
TreeMap<Integer, Integer> _tMap = new TreeMap<>();
public MyCalendarThree()
{
}
int maxCount = 0;
public int book( int start, int end )
{
_tMap.put( start, _tMap.getOrDefault( start, 0 ) + 1 );
_tMap.put( end, _tMap.getOrDefault( end, 0 ) - 1 );
int count = 0;
for ( int k : _tMap.keySet() )
{
maxCount = Math.max( maxCount, count + _tMap.get( k ) );
count += _tMap.get( k );
}
return maxCount;
}
public static void main( String[] args )
{
String[] op = { "MyCalendarThree", "book", "book", "book", "book", "book", "book", "book", "book", "book", "book" };
int[][] v = { {}, { 26, 35 }, { 26, 32 }, { 25, 32 }, { 18, 26 }, { 40, 45 }, { 19, 26 }, { 48, 50 }, { 1, 6 }, { 46, 50 }, { 11, 18 } };
MyCalendarThree myCalendar = new MyCalendarThree();
for ( int i = 1; i < op.length; i++ )
System.out.println( myCalendar.book( v[i][0], v[i][1] ) );
}
}
/**
* Your MyCalendarThree object will be instantiated and called as such:
* MyCalendarThree obj = new MyCalendarThree();
* int param_1 = obj.book(start,end);
*/