-
Notifications
You must be signed in to change notification settings - Fork 0
252. Meeting Rooms #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| ```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.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
本筋ではないですが、問題固有のクラス (Interval) がある場合、一回は定義部分を記載いただけるとレビュワーとしては助かると思いました。
252. Meeting Rooms
次回予告: 253. Meeting Rooms II