Skip to content

Conversation

@skypenguins
Copy link
Owner

252. Meeting Rooms

次回予告: 253. Meeting Rooms II

@skypenguins skypenguins self-assigned this Sep 25, 2025
```py
class Solution:
def canAttendMeetings(self, intervals: List[Interval]) -> bool:
sorted_intervals = sorted(intervals, key=lambda x: x.end)
Copy link

Choose a reason for hiding this comment

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

個人的にはinterval.startを見ていくのでx.startでsortした方が分かりやすい気がしました。

for interval in sorted_intervals:
if interval.start < last_meeting_end:
return False
last_meeting_end = interval.end
Copy link

@potrue potrue Sep 26, 2025

Choose a reason for hiding this comment

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

last_meetingそれ自体を変数に格納してもいいかもしれないと思いました。

if interval.start < last_interval.end:
    return False
last_interval = interval

みたいな感じです。質的に同じものを比較しているということがわかりやすくなる気がします。

class Solution:
def canAttendMeetings(self, intervals: List[Interval]) -> bool:
sorted_intervals = sorted(intervals, key=lambda interval: interval.start)
previous_interval_end = -1
Copy link

Choose a reason for hiding this comment

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

(指名されてないですがすみません)
-1はちょっと個人的には、意図を汲みにくいマジックナンバーの感じがしますかね。

def canAttendMeetings(self, intervals: List[Interval]) -> bool:
sorted_intervals = sorted(intervals, key=lambda x: x.end)
last_meeting_end = -1
for interval in sorted_intervals:
Copy link

Choose a reason for hiding this comment

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

好みですが、直接
for interval in sorted(intervals, key=lambda x: x.end):
の方がわかりやすい気がしてます。

### 解答(AC)
```py
class Solution:
def canAttendMeetings(self, intervals: List[Interval]) -> bool:

Choose a reason for hiding this comment

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

本筋ではないですが、問題固有のクラス (Interval) がある場合、一回は定義部分を記載いただけるとレビュワーとしては助かると思いました。

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