File tree Expand file tree Collapse file tree 3 files changed +106
-0
lines changed
solution/0700-0799/0731.My Calendar II Expand file tree Collapse file tree 3 files changed +106
-0
lines changed Original file line number Diff line number Diff line change @@ -208,6 +208,43 @@ func (this *MyCalendarTwo) Book(start int, end int) bool {
208208 */
209209```
210210
211+ #### TypeScript
212+
213+ ``` ts
214+ class MyCalendarTwo {
215+ private events: [number , number ][];
216+ private overlaps: [number , number ][];
217+
218+ constructor () {
219+ this .events = [];
220+ this .overlaps = [];
221+ }
222+
223+ book(start : number , end : number ): boolean {
224+ for (const [s, e] of this .overlaps ) {
225+ if (Math .max (start , s ) < Math .min (end , e )) {
226+ return false ;
227+ }
228+ }
229+
230+ for (const [s, e] of this .events ) {
231+ if (Math .max (start , s ) < Math .min (end , e )) {
232+ this .overlaps .push ([Math .max (start , s ), Math .min (end , e )]);
233+ }
234+ }
235+
236+ this .events .push ([start , end ]);
237+ return true ;
238+ }
239+ }
240+
241+ /**
242+ * Your MyCalendarTwo object will be instantiated and called as such:
243+ * var obj = new MyCalendarTwo()
244+ * var param_1 = obj.book(start,end)
245+ */
246+ ```
247+
211248#### JavaScript
212249
213250``` js
Original file line number Diff line number Diff line change @@ -206,6 +206,43 @@ func (this *MyCalendarTwo) Book(start int, end int) bool {
206206 */
207207```
208208
209+ #### TypeScript
210+
211+ ``` ts
212+ class MyCalendarTwo {
213+ private events: [number , number ][];
214+ private overlaps: [number , number ][];
215+
216+ constructor () {
217+ this .events = [];
218+ this .overlaps = [];
219+ }
220+
221+ book(start : number , end : number ): boolean {
222+ for (const [s, e] of this .overlaps ) {
223+ if (Math .max (start , s ) < Math .min (end , e )) {
224+ return false ;
225+ }
226+ }
227+
228+ for (const [s, e] of this .events ) {
229+ if (Math .max (start , s ) < Math .min (end , e )) {
230+ this .overlaps .push ([Math .max (start , s ), Math .min (end , e )]);
231+ }
232+ }
233+
234+ this .events .push ([start , end ]);
235+ return true ;
236+ }
237+ }
238+
239+ /**
240+ * Your MyCalendarTwo object will be instantiated and called as such:
241+ * var obj = new MyCalendarTwo()
242+ * var param_1 = obj.book(start,end)
243+ */
244+ ```
245+
209246#### JavaScript
210247
211248``` js
Original file line number Diff line number Diff line change 1+ class MyCalendarTwo {
2+ private events : [ number , number ] [ ] ;
3+ private overlaps : [ number , number ] [ ] ;
4+
5+ constructor ( ) {
6+ this . events = [ ] ;
7+ this . overlaps = [ ] ;
8+ }
9+
10+ book ( start : number , end : number ) : boolean {
11+ for ( const [ s , e ] of this . overlaps ) {
12+ if ( Math . max ( start , s ) < Math . min ( end , e ) ) {
13+ return false ;
14+ }
15+ }
16+
17+ for ( const [ s , e ] of this . events ) {
18+ if ( Math . max ( start , s ) < Math . min ( end , e ) ) {
19+ this . overlaps . push ( [ Math . max ( start , s ) , Math . min ( end , e ) ] ) ;
20+ }
21+ }
22+
23+ this . events . push ( [ start , end ] ) ;
24+ return true ;
25+ }
26+ }
27+
28+ /**
29+ * Your MyCalendarTwo object will be instantiated and called as such:
30+ * var obj = new MyCalendarTwo()
31+ * var param_1 = obj.book(start,end)
32+ */
You can’t perform that action at this time.
0 commit comments