Skip to content

Conversation

@Satorien
Copy link
Owner

@Satorien Satorien commented Jan 2, 2026

def canAttendMeetings(self, intervals: List[Interval]) -> bool:
heapq.heapify(intervals)

previous_end = -1
Copy link

Choose a reason for hiding this comment

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

問題の制約が0以上かもしれませんが、変なのを突っ込まれる可能性があるので、個人的には好みません。

これは一種の番兵なのでなくても書けるし、len(intervals) が正であることを確認したら intervals[0].start などでもいいですね。

Comment on lines +91 to +96
def interval_lt(self, other):
if self.start < other.start:
return True
return False

Interval.__lt__ = interval_lt

Choose a reason for hiding this comment

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

無理やり __lt__ を実装できるの面白いですね。

    def interval_lt(self, other):
        return self.start < other.start

でよいと思いました。
heapify を使うと in-place に置き換えられるので注意が必要だなと思いました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants