-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyCalendar.java
More file actions
executable file
·39 lines (33 loc) · 1.01 KB
/
MyCalendar.java
File metadata and controls
executable file
·39 lines (33 loc) · 1.01 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Neel_Kapadia
*/
import java.util.*;
public class MyCalendar {
static TreeMap<Integer, Integer> book;
boolean check = false;
public MyCalendar() {
book = new TreeMap<>();
}
public boolean book(int start, int end) {
Integer prev = book.floorKey(start),
next = book.ceilingKey(start);
if ((prev == null || book.get(prev) <= start) && (next == null || end <= next)) {
book.put(start, end);
return true;
}
return false;
}
public static void main(String[] args) {
MyCalendar m = new MyCalendar();
System.out.println(m.book(10, 20));
System.out.println(m.book(15, 25));
System.out.println(m.book(20, 30));
System.out.println(m.book(12, 18));
}
}