Leetcode
2020.04.15 14:10

# 729. My Calendar I

조회 수 98 추천 수 0 댓글 0
?

#### 단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

#### 단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

Implement a `MyCalendar` class to store your events. A new event can be added if adding the event will not cause a double booking.

Your class will have the method, `book(int start, int end)`. Formally, this represents a booking on the half open interval `[start, end)`, the range of real numbers `x` such that `start <= x < end`.

double booking happens when two events have some non-empty intersection (ie., there is some time that is common to both events.)

For each call to the method `MyCalendar.book`, return `true` if the event can be added to the calendar successfully without causing a double booking. Otherwise, return `false` and do not add the event to the calendar.

Your class will be called like this: `MyCalendar cal = new MyCalendar();` `MyCalendar.book(start, end)`

Example 1:

```MyCalendar();
MyCalendar.book(10, 20); // returns true
MyCalendar.book(15, 25); // returns false
MyCalendar.book(20, 30); // returns true
Explanation:
The first event can be booked.  The second can't because time 15 is already booked by another event.
The third event can be booked, as the first event takes every time less than 20, but not including 20.
```

Note:

• The number of calls to `MyCalendar.book` per test case will be at most `1000`.
• In calls to `MyCalendar.book(start, end)``start` and `end` are integers in the range `[0, 10^9]`.

```class MyCalendar {
List<int[]> list;

public MyCalendar() {
list = new ArrayList<>();
}

public boolean book(int start, int end) {
//for(int i=0; i<list.size(); i++){
//    int[] item = list.get(i);
for(int[] item : list){
if(item[1]>start && end>item[0]){
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);
*/```

?

 제목+내용제목내용댓글이름닉네임아이디태그
List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
74 Leetcode 692. Top K Frequent Words 2020.04.15 87
73 Leetcode 2. Add Two Numbers 2020.04.14 90
72 Leetcode 731. My Calendar II 2020.04.15 94
71 Leetcode 75. Sort Colors 2020.04.14 95
70 Leetcode 347. Top K Frequent Elements 2020.04.14 96
69 Leetcode 430. Flatten a Multilevel Doubly Linked List 2020.04.06 98
68 Leetcode 23. Merge k Sorted Lists 2020.04.14 98
» Leetcode 729. My Calendar I 2020.04.15 98
66 Leetcode 253. Meeting Rooms II 2020.04.15 98
65 Leetcode 20. Valid Parentheses 2020.04.25 98
64 Leetcode 62. Unique Paths 2020.04.09 99
63 Leetcode 7. Reverse Integer 2020.04.28 100
62 Leetcode 946. Validate Stack Sequences 2020.04.08 101
61 Leetcode 973. K Closest Points to Origin 2020.04.15 101
60 Leetcode 852. Peak Index in a Mountain Array 2020.04.28 101
59 Leetcode 350. Intersection of Two Arrays II 2020.04.28 102
58 Leetcode 443. String Compression 2020.04.25 103
57 Leetcode 38. Count and Say 2020.04.25 103
56 Leetcode 53. Maximum Subarray 2020.04.28 106
55 Leetcode 3. Longest Substring Without Repeating Characters 2020.04.09 107
Board Pagination Prev 1 2 3 4 Next
/ 4