-
Notifications
You must be signed in to change notification settings - Fork 0
253. Meeting Rooms II #56
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
| } | ||
| int max_num_rooms = 0; | ||
| int num_rooms = 0; | ||
| for (const pair<int, int>& [_, num_change] : time_to_num_change) { |
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.
上で書かれているように auto を使っても良いかなと思いました。num_change が int だろうと下の行でわかりそうで、使わない _ の型を書くのは微妙かなという理由です。
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.
これは確かにそうですね。読むにあたってノイズとなる情報かもしれません。
| num_rooms += num_change; | ||
| max_num_rooms = max(max_num_rooms, num_rooms); | ||
| } | ||
| return max_num_rooms; |
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.
問題文の表現に合わせて min を使った方が自然かなと思いました。
| https://github.com/ryosuketc/leetcode_arai60/pull/56/files | ||
| https://github.com/Ryotaro25/leetcode_first60/pull/61/files | ||
|
|
||
| cppのmapやunordered_mapはpythonでいうdefaultdictみたいな振る舞いをするらしい。([]で存在しない要素にアクセスしようとすると自動でvalueがコンストラクタから初期化される) |
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.
レファレンスはこの辺りでしょうか。
https://en.cppreference.com/w/cpp/container/map/operator_at.html
Returns a reference to the value that is mapped to a key equivalent to key or x respectively, performing an insertion if such key does not already exist.
| ++time_to_num_change[interval[0]]; | ||
| --time_to_num_change[interval[1]]; | ||
| } | ||
| int max_num_rooms = 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.
好みですが、min_required_rooms などの方が素直に読めそうだなとは思います (ただ関数の返り値であることは明らかなので、これで十分とは思いますが)。
https://leetcode.com/problems/meeting-rooms-ii/
https://leetcode.ca/2016-08-09-253-Meeting-Rooms-II/