Skip to content

Commit f39de4c

Browse files
week13 mission meeting-rooms-ii
1 parent e494ff9 commit f39de4c

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
- ๋ฌธ์ œ
2+
- ์œ ๋ฃŒ: https://leetcode.com/problems/meeting-rooms-ii/
3+
- ๋ฌด๋ฃŒ: https://www.lintcode.com/problem/919/
4+
- ํ’€์ด: https://algorithm.jonghoonpark.com/2024/07/22/leetcode-253
5+
6+
```java
7+
public class Solution {
8+
public int minMeetingRooms(List<Interval> intervals) {
9+
intervals = intervals.stream().sorted(Comparator.comparingInt(o -> o.start)).toList();
10+
11+
List<List<Interval>> days = new ArrayList<>();
12+
13+
for(Interval interval : intervals) {
14+
boolean added = false;
15+
for (List<Interval> day : days) {
16+
day.add(interval);
17+
if (canAttendMeetings(day)) {
18+
added = true;
19+
break;
20+
}
21+
day.remove(day.size() - 1);
22+
}
23+
24+
if(!added) {
25+
List<Interval> newDay = new ArrayList<>();
26+
newDay.add(interval);
27+
days.add(newDay);
28+
}
29+
}
30+
31+
return days.size();
32+
}
33+
34+
public boolean canAttendMeetings(List<Interval> intervals) {
35+
for (int i = 0; i < intervals.size() - 1; i++) {
36+
if(intervals.get(i).end > intervals.get(i+1).start) {
37+
return false;
38+
}
39+
}
40+
return true;
41+
}
42+
}
43+
44+
class Interval {
45+
public int start, end;
46+
47+
public Interval(int start, int end) {
48+
this.start = start;
49+
this.end = end;
50+
}
51+
52+
@Override
53+
public String toString() {
54+
return "{" + start + ", " + end + "}";
55+
}
56+
}
57+
```
58+
59+
### TC, SC
60+
61+
days์˜ ๊ธธ์ด๋ฅผ m ์ด๋ผ๊ณ  ํ–ˆ์„ ๋•Œ, ์‹œ๊ฐ„ ๋ณต์žก๋„๋Š” `O(n^2 * m)` ๊ณต๊ฐ„ ๋ณต์žก๋„๋Š” `O(n)` ์ด๋‹ค. m์€ ์ตœ์•…์˜ ๊ฒฝ์šฐ n์ด ๋  ์ˆ˜ ์žˆ๋‹ค.

0 commit comments

Comments
ย (0)