Skip to content

252: Meeting Rooms#55

Open
garunitule wants to merge 1 commit intomainfrom
252
Open

252: Meeting Rooms#55
garunitule wants to merge 1 commit intomainfrom
252

Conversation

@garunitule
Copy link
Copy Markdown
Owner

@garunitule garunitule commented Mar 23, 2026

252. Meeting Rooms
253. Meeting Rooms II

問題文

premiumだったので問題文掲載

Given an array of meeting time intervals where intervals[i] = [starti, endi], determine if a person could attend all meetings.

Example 1:

Input: intervals = [[0,30],[5,10],[15,20]]
Output: false
Example 2:

Input: intervals = [[7,10],[2,4]]
Output: true


# step2: 30分
leetcodeの解法を見たら、全組み合わせを確認する解法とソートして確認する解法だった。
Pythonだと空間計算量はO(n)だけど、JavaだとO(logn)とのこと。実装アルゴリズムが異なるらしい。
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

何のことかと思ってGeminiに聞いてみたところ

  • PythonはTimsort. 空間計算量は O(n)
  • JavaではDual-Pivot Quicksort. 空間計算量は O(log n)
    • ただし Arrays.sort() でプリミティブ型をソートする場合。そうでない場合はTimsortが使われる

ということなんですね(裏取りできていませんが)。

class Solution:
def canAttendMeetings(self, intervals: List[List[int]]) -> bool:
intervals_sorted_by_start = sorted(intervals, key=lambda interval: interval[0])
for i in range(len(intervals_sorted_by_start) - 1):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

itertools.pairwise を使うと分かりやすく書けます。趣味の範囲だと思います。

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.

2 participants