Open
Conversation
nodchip
reviewed
Mar 25, 2024
| class Solution: | ||
| def minMeetingRooms(self, intervals: List[List[int]]) -> int: | ||
| # intervalは左閉右開区間なのでsortした際にENDがSTARTより先に来て欲しい | ||
| MTG_START = 1 |
There was a problem hiding this comment.
チーム内で合意形成が得られている場合を除き、変数名の単語はフルスペルで書くことをお勧めいたします。
| ```python | ||
| class Solution: | ||
| def minMeetingRooms(self, intervals: List[List[int]]) -> int: | ||
| EVENT_START = 1 |
There was a problem hiding this comment.
問題領域の単語をそのまま使ったほうが良いと思います。ここでは問題文中の meeting という単語を使うとよいと思います。
|
|
||
|
|
||
| events.sort() | ||
| num_of_rooms = 0 |
There was a problem hiding this comment.
num は number of の省略形として比較的よくつかわれるらしいため、 num_rooms でよいと思います。ただし、チームでコードを書く際は、チーム内で合意形成が得られているかは確認したほうが良いと思います。
| events.append((end_time, EVENT_END)) | ||
|
|
||
| events.sort() | ||
| ongoing_meetings = 0 |
There was a problem hiding this comment.
ongoing_meetings という変数名ですと、開催中のミーティングを表す何らかの情報のリストを連想します。変数名に、 num・number など は入れたほうが良いと思います。したの needed_rooms も同様です。
Owner
Author
There was a problem hiding this comment.
ありがとうございます。コメント反映して書き直しました。
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|
よいと思います。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://leetcode.com/problems/meeting-rooms-ii/