-
Notifications
You must be signed in to change notification settings - Fork 0
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
253. Meeting Rooms II #62
base: main
Are you sure you want to change the base?
Conversation
class Solution: | ||
def minMeetingRooms(self, intervals: List[List[int]]) -> int: | ||
# intervalは左閉右開区間なのでsortした際にENDがSTARTより先に来て欲しい | ||
MTG_START = 1 |
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.
チーム内で合意形成が得られている場合を除き、変数名の単語はフルスペルで書くことをお勧めいたします。
```python | ||
class Solution: | ||
def minMeetingRooms(self, intervals: List[List[int]]) -> int: | ||
EVENT_START = 1 |
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.
問題領域の単語をそのまま使ったほうが良いと思います。ここでは問題文中の meeting という単語を使うとよいと思います。
|
||
|
||
events.sort() | ||
num_of_rooms = 0 |
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.
num は number of の省略形として比較的よくつかわれるらしいため、 num_rooms でよいと思います。ただし、チームでコードを書く際は、チーム内で合意形成が得られているかは確認したほうが良いと思います。
events.append((end_time, EVENT_END)) | ||
|
||
events.sort() | ||
ongoing_meetings = 0 |
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.
ongoing_meetings という変数名ですと、開催中のミーティングを表す何らかの情報のリストを連想します。変数名に、 num・number など は入れたほうが良いと思います。したの needed_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[List[int]]) -> int:
MEETING_START = 1
MEETING_END = 0
events = []
for start_time, end_time in intervals:
events.append((start_time, MEETING_START))
events.append((end_time, MEETING_END))
events.sort()
num_ongoing_meetings = 0
num_needed_rooms = 0
for event_time, event_type in events:
if event_type == MEETING_END:
num_ongoing_meetings -= 1
continue
num_ongoing_meetings += 1
num_needed_rooms = max(num_needed_rooms, num_ongoing_meetings)
return num_needed_rooms
よいと思います。 |
https://leetcode.com/problems/meeting-rooms-ii/