-
Notifications
You must be signed in to change notification settings - Fork 0
253. Meeting Rooms II #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| class Solution: | ||
| def minMeetingRooms(self, intervals: List[Interval]) -> int: | ||
| intervals.sort(key=lambda x: x.start) | ||
| rooms = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
個人的には、「各部屋の最終使用時刻(鍵返却時刻)」なので、rooms でないほうが読みやすいように思います。
| ## Step1 | ||
| - 252.と同様の考え方で、前の会議終了時刻>次の会議開始時刻となった場合に会議日数をインクリメントしていく方針とした | ||
| - しかし、すべての会議を調べるわけではないので誤って会議日数をカウントしてしまう | ||
| - 最大の会議日数=会議数となるため、すべての会議を調べていき会議時刻が重複しなかったら最大の会議日数からデクリメントする方針とした |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これは、その後で使う会議室 X を決めてくっつけるみたいな考え方ですが、その会議室 X に何度もくっつけてしまうことがあるのでうまくいきませんね。
| heapq.heappop(rooms) | ||
| heapq.heappush(rooms, interval.end) | ||
|
|
||
| return len(rooms) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
自分がこの別解のやり方を見たことがなかったのもあると思うのですが、少し理解に時間がかかりました。個人的にはカウントをインクリメント/デクリメントさせていくやり方の方がわかりやすかったです。
|
|
||
| class Solution: | ||
| def minMeetingRooms(self, intervals: List[Interval]) -> int: | ||
| intervals.sort(key=lambda x: x.start) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
STEP2と違い、入力を書き換えている点が気になりました。
253. Meeting Rooms II
次回予告: 22. Generate Parentheses