1
1
import {
2
- Interval ,
3
- } from '/opt/node/lib/lintcode/index.js' ;
4
-
2
+ Interval ,
3
+ } from '/opt/node/lib/lintcode/index.js' ;
4
+
5
+ /**
6
+ * Definition of Interval:
7
+ * class Interval {
8
+ * constructor(start, end) {
9
+ * this.start = start;
10
+ * this.end = end;
11
+ * }
12
+ * }
13
+ */
14
+
15
+ export class Solution {
5
16
/**
6
- * Definition of Interval:
7
- * class Interval {
8
- * constructor(start, end) {
9
- * this.start = start;
10
- * this.end = end;
11
- * }
12
- * }
17
+ * @param intervals: an array of meeting time intervals
18
+ * @return : if a person could attend all meetings
13
19
*/
14
-
15
- export class Solution {
16
- /**
17
- * @param intervals: an array of meeting time intervals
18
- * @return : if a person could attend all meetings
19
- */
20
- canAttendMeetings ( intervals ) {
21
- const sort = intervals . sort ( ( a , b ) => {
22
- if ( a [ 1 ] === b [ 1 ] ) {
23
- return a [ 0 ] - b [ 0 ] ;
24
- }
20
+ canAttendMeetings ( intervals ) {
21
+ const sort = intervals . sort ( ( a , b ) => {
22
+ if ( a [ 1 ] === b [ 1 ] ) {
23
+ return a [ 0 ] - b [ 0 ] ;
24
+ }
25
25
26
- return a [ 1 ] - b [ 1 ] ;
27
- } )
28
-
29
- for ( let i = 0 ; i < sort . length - 2 ; i ++ ) {
30
- const current = sort [ i ] [ 1 ] ;
31
- const next = sort [ i + 1 ] [ 0 ] ;
26
+ return a [ 1 ] - b [ 1 ] ;
27
+ } )
28
+
29
+ for ( let i = 0 ; i < sort . length - 2 ; i ++ ) {
30
+ const current = sort [ i ] [ 1 ] ;
31
+ const next = sort [ i + 1 ] [ 0 ] ;
32
32
33
- if ( current > next ) {
34
- return false ;
35
- }
33
+ if ( current > next ) {
34
+ return false ;
36
35
}
37
-
38
- return true ;
39
36
}
37
+
38
+ return true ;
40
39
}
40
+ }
41
41
42
- // μκ°λ³΅μ‘λ O(nlogn) -> sort ν¨μ μ¬μ©μΌλ‘ μΈν μκ°λ³΅μ‘λ
43
- // 곡κ°λ³΅μ‘λ O(1) -> μ¬μ©νλ μλ£κ΅¬μ‘°, ν¨μμ€νμ€ν μμ
42
+ // μκ°λ³΅μ‘λ O(nlogn) -> sort ν¨μ μ¬μ©μΌλ‘ μΈν μκ°λ³΅μ‘λ
43
+ // 곡κ°λ³΅μ‘λ O(1) -> μ¬μ©νλ μλ£κ΅¬μ‘°, ν¨μμ€νμ€ν μμ
44
44
45
-
0 commit comments