Skip to content

Conversation

@Ryotaro25
Copy link
Owner

問題へのリンク
https://leetcode.com/problems/meeting-rooms/description/

問題文(プレミアムの場合)
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

Constraints:
0 <= intervals.length <= 104
intervals[i].length == 2
0 <= starti < endi <= 106

備考

次に解く問題の予告

フォルダ構成
LeetCodeの問題ごとにフォルダを作成します。
フォルダ内は、step1.cpp、step2.cpp、step3.cppとsort.cppとtwo_keys.cppとmemo.mdとなります。

memo.md内に各ステップで感じたことを追記します。

sort(intervals.begin(), intervals.end());
for (int i = 0; i < intervals.size() - 1; i++) {
// 現在の終了時間 > 次の開始時間 で比較
if (intervals[i][1] > intervals[i + 1][0]) {
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.

@oda
レビューありがとうございます。
prev_end_timeという変数をを作りました。
イメージは下記の通りです。
前回の終了時間を作業者に伝え、重複するのかしないのか確認させます。しない場合は、次の作業者に今回の終了時間を伝えます。

80fe28d

bool canAttendMeetings(vector<vector<int>>& intervals) {
set<int> used_hours;
for (const vector<int>& interval : intervals) {
// intervalごとにstartからendまでを埋めていく
Copy link

Choose a reason for hiding this comment

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

これでもいいですが、たとえば、時間が double になったときに使えないなど、色々と制約はありそうですね。
そういったことも考えていただけるとありがたいです。

Copy link
Owner Author

Choose a reason for hiding this comment

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

@oda
hour++の部分であったり、埋めていく方式だとそもそもデータ量が多くなりすぎて探索できなさ等ですね。
違う型で渡された場合にも問題ないのか、拡張できるのかは意識するようにいたします。

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.

3 participants