Skip to content

Commit b56d702

Browse files
committed
Meeting room
1 parent 97a452c commit b56d702

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

meeting-rooms/jaejeong1.java

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

0 commit comments

Comments
 (0)