Skip to content

Commit 9ee2966

Browse files
author
Jeongwon Na
committed
meeting rooms solution
1 parent a1e93a8 commit 9ee2966

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

meeting-rooms/njngwn.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Definition of Interval:
3+
* public class Interval {
4+
* int start, end;
5+
* Interval(int start, int end) {
6+
* this.start = start;
7+
* this.end = end;
8+
* }
9+
* }
10+
*/
11+
12+
public class Solution {
13+
/**
14+
* @param intervals: an array of meeting time intervals
15+
* @return: if a person could attend all meetings
16+
*/
17+
public boolean canAttendMeetings(List<Interval> intervals) {
18+
// Write your code here
19+
intervals.sort((a, b) -> a.start - b.start); // sort by start time
20+
21+
int prevEndTime = 0;
22+
for (Interval meeting : intervals) {
23+
if (meeting.start < prevEndTime) {
24+
return false;
25+
}
26+
prevEndTime = meeting.end;
27+
}
28+
return true;
29+
}
30+
}

0 commit comments

Comments
 (0)