Skip to content

Commit fb62b61

Browse files
authored
Merge pull request #1618 from YoungSeok-Choi/feature/week-13
[YoungSeok-Choi] Week 13 solutions
2 parents 0ffb635 + 167967c commit fb62b61

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

meeting-rooms/YoungSeok-Choi.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import java.util.Collections;
2+
import java.util.Comparator;
3+
import java.util.List;
4+
5+
class Interval {
6+
int start, end;
7+
8+
Interval(int start, int end) {
9+
this.start = start;
10+
this.end = end;
11+
}
12+
}
13+
14+
class Solution {
15+
16+
public boolean canAttendMeetings(List<Interval> intervals) {
17+
Collections.sort(intervals, new Comparator<Interval>() {
18+
@Override
19+
public int compare(Interval i1, Interval i2) {
20+
if (i1.start == i2.start) {
21+
return i1.end - i2.end;
22+
}
23+
24+
return i1.start - i2.start;
25+
}
26+
});
27+
28+
int prevEnd = -987654321;
29+
for (Interval anInt : intervals) {
30+
if (anInt.start < prevEnd) {
31+
return false;
32+
}
33+
34+
prevEnd = anInt.end;
35+
}
36+
37+
return true;
38+
}
39+
}

0 commit comments

Comments
 (0)