-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyCalendar.java
More file actions
57 lines (46 loc) · 1.03 KB
/
MyCalendar.java
File metadata and controls
57 lines (46 loc) · 1.03 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
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.TreeSet;
class MyCalendar
{
public MyCalendar()
{
}
TreeSet<Integer> _set = new TreeSet<>();
public boolean book( int start, int end )
{
_set.add( start );
_set.add( -end );
int k = 0, run = 0;
for ( int m : _set )
{
if ( m > 0 )
run++;
else
run--;
if ( run > 1 )
{
_set.remove( start );
_set.remove( -end );
return false;
}
}
return true;
}
/**
* Your MyCalendar object will be instantiated and called as such:
* MyCalendar obj = new MyCalendar();
* boolean param_1 = obj.book(start,end);
*/
public static void main( String[] args )
{
String[] op = { "MyCalendar", "book", "book", "book" };
int[][] v = { {}, { 10, 20 }, { 15, 25 }, { 20, 30 } };
MyCalendar myCalendar = new MyCalendar();
for ( int i = 1; i < op.length; i++ )
System.out.println( myCalendar.book( v[i][0], v[i][1] ) );
}
}
/**
* Your MyCalendar object will be instantiated and called as such:
* MyCalendar obj = new MyCalendar();
* boolean param_1 = obj.book(start,end);
*/