Skip to content

1011. Capacity To Ship Packages Within D Days#42

Open
tom4649 wants to merge 3 commits intomainfrom
1011.Capacity-To-Ship-Packages-Within-D-Days
Open

1011. Capacity To Ship Packages Within D Days#42
tom4649 wants to merge 3 commits intomainfrom
1011.Capacity-To-Ship-Packages-Within-D-Days

Conversation

@tom4649
Copy link
Copy Markdown
Owner

@tom4649 tom4649 commented Apr 5, 2026

Comment thread 1011/sol2.py
def shipWithinDays(self, weights: list[int], days: int) -> int:
def can_ship(capacity):
used_days = 1
shipped_weight_on_current_day = 0
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

個人的にはここの変数名はtotal_weightとかで充分だと思いました。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

確かに長いですね。
「変数名は省略するな」を意識していたのですが、「長くて良い」という意味ではないので冗長にならないように気をつけます。

Comment thread 1011/sol1.py

maximum_value = min(sum(weights), MAXIMUM_WEIGHT * (len(weights) // days + 1))

return bisect.bisect_left(range(1, maximum_value), True, key=can_ship) + 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.

すでに 35.search insert position で練習済みかと思いますが、二分探索を自力で実装するのがこの問題の期待値なのかなと思いました。

Copy link
Copy Markdown
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.

3 participants