Conversation
oda
reviewed
Jan 4, 2026
| def canAttendMeetings(self, intervals: List[Interval]) -> bool: | ||
| heapq.heapify(intervals) | ||
|
|
||
| previous_end = -1 |
There was a problem hiding this comment.
問題の制約が0以上かもしれませんが、変なのを突っ込まれる可能性があるので、個人的には好みません。
これは一種の番兵なのでなくても書けるし、len(intervals) が正であることを確認したら intervals[0].start などでもいいですね。
tokuhirat
reviewed
Jan 5, 2026
Comment on lines
+91
to
+96
| def interval_lt(self, other): | ||
| if self.start < other.start: | ||
| return True | ||
| return False | ||
|
|
||
| Interval.__lt__ = interval_lt |
There was a problem hiding this comment.
無理やり __lt__ を実装できるの面白いですね。
def interval_lt(self, other):
return self.start < other.startでよいと思いました。
heapify を使うと in-place に置き換えられるので注意が必要だなと思いました。
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://neetcode.io/problems/meeting-schedule/question