Skip to content

1011_capacity_to_ship_packages_within_d_days#44

Open
dxxsxsxkx wants to merge 1 commit into33_search_in_rotated_sorted_arrayfrom
1011_capacity_to_ship_packages_within_d_days
Open

1011_capacity_to_ship_packages_within_d_days#44
dxxsxsxkx wants to merge 1 commit into33_search_in_rotated_sorted_arrayfrom
1011_capacity_to_ship_packages_within_d_days

Conversation

@dxxsxsxkx
Copy link
Copy Markdown
Owner

while (min_capacity < max_capacity) {
int mid = min_capacity + (max_capacity - min_capacity) / 2;

// Can you ship `weights` within `days` with `capacity`?
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

このコメントも shipWithinDays と同じフォーマットで、関数の定義以下に書くと統一感が出ると思いました。
この箇所では命名が良いので、コメントは無くても伝わりました。

}
private:
bool canShip(std::vector<int>& weights, int days, int capacity) {
int days_spent = 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.

_used よりも _spent の方がより分かりやすいですね 👍 細かいところの改善も検討されていて素晴らしいと思いました。


- [参照](https://github.com/potrue/leetcode/pull/44/changes#r2276124905)

`std::accumulate` の代わりに [`std::reduce`](https://cpprefjp.github.io/reference/numeric/reduce.html)。C++17から。どっちがいいかは正直分からず。
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

C++に不慣れな私としては、accumulate の方が加算なのだなと想像しやすかったです。reduce は「たぶんデフォルトのオペレーションが加算なんだろうけど、リファレンスを見に行くか」となりました。

@mamo3gr
Copy link
Copy Markdown

mamo3gr commented Mar 13, 2026

いずれも読みやすかったです!

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