File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Interval } from "../home/lib/index" ;
2+ /**
3+ * Definition of Interval:
4+ * export class Interval {
5+ * start :number;
6+ * end :number;
7+ * constructor(start :number, end :number) {
8+ * this.start = start;
9+ * this.end = end;
10+ * }
11+ * }
12+ */
13+
14+ export class Solution {
15+ /**
16+ * Time Complexity: O(nlogn)
17+ * Space Complexity: O(1)
18+ *
19+ * @param intervals: an array of meeting time intervals
20+ * @return : if a person could attend all meetings
21+ */
22+ canAttendMeetings ( intervals : Interval [ ] ) : boolean {
23+ if ( intervals . length <= 1 ) return true ;
24+
25+ intervals . sort ( ( a , b ) => a . start - b . start ) ;
26+
27+ let prevEnd = intervals [ 0 ] . end ;
28+ for ( let i = 1 ; i < intervals . length ; i ++ ) {
29+ const currentStart = intervals [ i ] . start ;
30+ const currentEnd = intervals [ i ] . end ;
31+
32+ if ( prevEnd > currentStart ) {
33+ return false ;
34+ }
35+ prevEnd = currentEnd ;
36+ }
37+
38+ return true ;
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments