File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change 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์ด ๋ ์ ์๋ค.
You canโt perform that action at this time.
0 commit comments