Conversation
potrue
reviewed
Sep 26, 2025
| ```py | ||
| class Solution: | ||
| def canAttendMeetings(self, intervals: List[Interval]) -> bool: | ||
| sorted_intervals = sorted(intervals, key=lambda x: x.end) |
There was a problem hiding this comment.
個人的にはinterval.startを見ていくのでx.startでsortした方が分かりやすい気がしました。
potrue
reviewed
Sep 26, 2025
| for interval in sorted_intervals: | ||
| if interval.start < last_meeting_end: | ||
| return False | ||
| last_meeting_end = interval.end |
There was a problem hiding this comment.
last_meetingそれ自体を変数に格納してもいいかもしれないと思いました。
if interval.start < last_interval.end:
return False
last_interval = interval
みたいな感じです。質的に同じものを比較しているということがわかりやすくなる気がします。
nittoco
reviewed
Sep 26, 2025
| class Solution: | ||
| def canAttendMeetings(self, intervals: List[Interval]) -> bool: | ||
| sorted_intervals = sorted(intervals, key=lambda interval: interval.start) | ||
| previous_interval_end = -1 |
There was a problem hiding this comment.
(指名されてないですがすみません)
-1はちょっと個人的には、意図を汲みにくいマジックナンバーの感じがしますかね。
nittoco
reviewed
Sep 26, 2025
| 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: |
There was a problem hiding this comment.
好みですが、直接
for interval in sorted(intervals, key=lambda x: x.end):
の方がわかりやすい気がしてます。
tokuhirat
reviewed
Sep 28, 2025
| ### 解答(AC) | ||
| ```py | ||
| class Solution: | ||
| def canAttendMeetings(self, intervals: List[Interval]) -> bool: |
There was a problem hiding this comment.
本筋ではないですが、問題固有のクラス (Interval) がある場合、一回は定義部分を記載いただけるとレビュワーとしては助かると思いました。
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.
252. Meeting Rooms
次回予告: 253. Meeting Rooms II