Skip to content

Conversation

katsukii
Copy link
Owner

問題

https://leetcode.com/problems/meeting-rooms-ii/

Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required.

Example 1:

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

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

Constraints:
1 <= intervals.length <= 104
0 <= starti < endi <= 106

言語

Java

次に解く問題

Reverse Linked List

@katsukii katsukii changed the title 253 253. Meeting Rooms II Apr 20, 2025
Comment on lines +74 to +76
if (intervals == null || intervals.length == 0) {
return 0;
}
Copy link

Choose a reason for hiding this comment

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

intervals == null はともかく、空ならば特に問題なく0が返りますか?

Copy link
Owner Author

Choose a reason for hiding this comment

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

はい、空配列の場合 intervals.length == 0 がtrueとなります。

- イベント変換: 各会議の開始時刻と終了時刻をそれぞれイベントとして配列に変換する
- 開始イベント: +1 カウント(会議室使用開始)
- 終了イベント: -1 カウント(会議室リリース)
- イベントソート: 両イベント配列を 2D 配列として一つの配列にマージして時刻順(昇順)にソートする。同時刻にイベントが複数存在する場合、終了イベント(-1)を優先する
Copy link

Choose a reason for hiding this comment

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

時刻ごとにいくつ増えるか減るか、と思うこともできますね。

全体的に問題ないかと思います。

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。

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