Skip to content

Conversation

@skypenguins
Copy link
Owner

253. Meeting Rooms II

次回予告: 22. Generate Parentheses

@skypenguins skypenguins self-assigned this Sep 28, 2025
class Solution:
def minMeetingRooms(self, intervals: List[Interval]) -> int:
intervals.sort(key=lambda x: x.start)
rooms = []
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

個人的には、「各部屋の最終使用時刻(鍵返却時刻)」なので、rooms でないほうが読みやすいように思います。

## Step1
- 252.と同様の考え方で、前の会議終了時刻>次の会議開始時刻となった場合に会議日数をインクリメントしていく方針とした
- しかし、すべての会議を調べるわけではないので誤って会議日数をカウントしてしまう
- 最大の会議日数=会議数となるため、すべての会議を調べていき会議時刻が重複しなかったら最大の会議日数からデクリメントする方針とした
Copy link

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)
Copy link

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

STEP2と違い、入力を書き換えている点が気になりました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants