-
Notifications
You must be signed in to change notification settings - Fork 0
253. Meeting Rooms II #61
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
| RoomCounter result = accumulate(time_with_labels.begin(), time_with_labels.end(), | ||
| RoomCounter{0, 0}, updateRoomCounter); |
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 で開いて書いたほうが読みやすいし、後々書き換えやすいだろうと思います。
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.
@oda
Pythonのfoldを使った解法があったので調べたところC++ではaccumulateが似た機能を持つとございました。
step1~step3のようにforで回す方が自分も好みでした。
253.MeetingRoomsII/accumulate.cpp
Outdated
| time_with_labels.emplace_back(interval[0], "start"); | ||
| time_with_labels.emplace_back(interval[1], "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.
end, start がこの辞書順であることを利用していることに気がつけというのは、結構パズルを作っていると思います。
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.
| int min_required_rooms = 0; | ||
| int current_used_rooms = 0; | ||
| // 時間ごとの鍵の貸し出し数のうち最大のものを探す | ||
| for (const auto& [time, num_used_rooms] : time_to_room_reservation) { |
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.
time は C++ では time.h の time を思い浮かべますね。後使っていないので、警告が出ることがあるが、structured bindings では難しいなどの話があります。
https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0
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.
@oda
確かに調べたところtime.hの中にtimeは既にありました。
https://learn.microsoft.com/ja-jp/cpp/c-runtime-library/reference/time-time32-time64?view=msvc-170
ありそうな言葉は調べる癖をつけないとですね。occupied_timeとしてみました。
| int min_required_rooms = 0; | ||
| int current_using_rooms = 0; | ||
| // 時間ごとの鍵の貸し出し数のうち最大のものを探す | ||
| for (const auto& [using_time, num_key] : num_keys) { |
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.
using_time は言語感覚に合わないですが、しかしベターなアイディアがあるわけではありません。
問題へのリンク
https://leetcode.com/problems/meeting-rooms-ii/description/
問題文(プレミアムの場合)
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
備考
次に解く問題の予告
Is Subsequence
フォルダ構成
LeetCodeの問題ごとにフォルダを作成します。
フォルダ内は、step1.cpp、step2.cpp、step3.cpp、accumulate.cpp、priority_queue.cppとmemo.mdとなります。
memo.md内に各ステップで感じたことを追記します。