Skip to content

Commit c9108b8

Browse files
committed
feat: add solutions to lc problem: No.0729
No.0729.My Calendar I
1 parent 053d2be commit c9108b8

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,42 @@ func (this *MyCalendar) Book(start int, end int) bool {
145145
*/
146146
```
147147

148+
### **C++**
149+
150+
```cpp
151+
class MyCalendar {
152+
public:
153+
map<int, int> m;
154+
155+
MyCalendar() {
156+
157+
}
158+
159+
bool book(int start, int end) {
160+
++m[start];
161+
--m[end];
162+
int s = 0;
163+
for (auto& [k, v] : m)
164+
{
165+
s += v;
166+
if (s > 1)
167+
{
168+
--m[start];
169+
++m[end];
170+
return false;
171+
}
172+
}
173+
return true;
174+
}
175+
};
176+
177+
/**
178+
* Your MyCalendar object will be instantiated and called as such:
179+
* MyCalendar* obj = new MyCalendar();
180+
* bool param_1 = obj->book(start,end);
181+
*/
182+
```
183+
148184
### **...**
149185
150186
```

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,42 @@ func (this *MyCalendar) Book(start int, end int) bool {
135135
*/
136136
```
137137

138+
### **C++**
139+
140+
```cpp
141+
class MyCalendar {
142+
public:
143+
map<int, int> m;
144+
145+
MyCalendar() {
146+
147+
}
148+
149+
bool book(int start, int end) {
150+
++m[start];
151+
--m[end];
152+
int s = 0;
153+
for (auto& [k, v] : m)
154+
{
155+
s += v;
156+
if (s > 1)
157+
{
158+
--m[start];
159+
++m[end];
160+
return false;
161+
}
162+
}
163+
return true;
164+
}
165+
};
166+
167+
/**
168+
* Your MyCalendar object will be instantiated and called as such:
169+
* MyCalendar* obj = new MyCalendar();
170+
* bool param_1 = obj->book(start,end);
171+
*/
172+
```
173+
138174
### **...**
139175
140176
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class MyCalendar {
2+
public:
3+
map<int, int> m;
4+
5+
MyCalendar() {
6+
7+
}
8+
9+
bool book(int start, int end) {
10+
++m[start];
11+
--m[end];
12+
int s = 0;
13+
for (auto& [k, v] : m)
14+
{
15+
s += v;
16+
if (s > 1)
17+
{
18+
--m[start];
19+
++m[end];
20+
return false;
21+
}
22+
}
23+
return true;
24+
}
25+
};
26+
27+
/**
28+
* Your MyCalendar object will be instantiated and called as such:
29+
* MyCalendar* obj = new MyCalendar();
30+
* bool param_1 = obj->book(start,end);
31+
*/

0 commit comments

Comments
 (0)