Skip to content

Commit 4e19f87

Browse files
authored
feat: add java solution to lc problem: NO.0729. My Calendar I (doocs#549)
1 parent c03f046 commit 4e19f87

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

solution/0700-0799/0729.My Calendar I/README.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,23 @@ MyCalendar.book(20, 30); // returns true
5555
<!-- 这里可写当前语言的特殊实现逻辑 -->
5656

5757
```java
58-
58+
class MyCalendar {
59+
List<int[]> calendar;
60+
61+
MyCalendar() {
62+
calendar = new ArrayList<>();
63+
}
64+
65+
public boolean book(int start, int end) {
66+
for (int[] item : calendar) {
67+
if (item[0] < end && item[1] > start) {
68+
return false;
69+
}
70+
}
71+
calendar.add(new int[]{start, end});
72+
return true;
73+
}
74+
}
5975
```
6076

6177
### **...**

solution/0700-0799/0729.My Calendar I/README_EN.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,23 @@ The third event can be booked, as the first event takes every time less than 20,
7878
### **Java**
7979

8080
```java
81-
81+
class MyCalendar {
82+
List<int[]> calendar;
83+
84+
MyCalendar() {
85+
calendar = new ArrayList<>();
86+
}
87+
88+
public boolean book(int start, int end) {
89+
for (int[] item : calendar) {
90+
if (item[0] < end && item[1] > start) {
91+
return false;
92+
}
93+
}
94+
calendar.add(new int[]{start, end});
95+
return true;
96+
}
97+
}
8298
```
8399

84100
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class MyCalendar {
2+
List<int[]> calendar;
3+
4+
MyCalendar() {
5+
calendar = new ArrayList<>();
6+
}
7+
8+
public boolean book(int start, int end) {
9+
for (int[] item : calendar) {
10+
if (item[0] < end && item[1] > start) {
11+
return false;
12+
}
13+
}
14+
calendar.add(new int[]{start, end});
15+
return true;
16+
}
17+
}

0 commit comments

Comments
 (0)