-
Notifications
You must be signed in to change notification settings - Fork 0
1011. Capacity To Ship Packages Within D Days #45
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
total_weight += weight | ||
return days_with_capacity + 1 <= days | ||
|
||
return bisect_left(range(sum(weights) + 1), True, key=can_be_shipped) |
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.
おお、range がランダムアクセスできて、空間計算量が O(1) なの知りませんでした。よく考えるとそりゃそうですね。
せっかくなので、lo=max(weights) を与えておくと探索範囲も同じになりますね。
こういう無駄なことしてました。
https://discord.com/channels/1084280443945353267/1233295449985650688/1246144715653513318
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.
良いと思います。
|
||
def can_be_shipped(capacity: int) -> bool: | ||
total_weight = 0 | ||
days_with_capacity = 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.
この変数名がちょっと分からなかったです。
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.
Can be shipped in N days with this capacity という気分でしょうが、days required か単に days かそのあたりじゃないかと思いますね。
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.
Can be shipped in N days with this capacity という気分でしょうが
そんな感じでした。たしかにdays_requiredの方が良いですね
total_weight += weight | ||
return days_with_capacity + 1 <= days | ||
|
||
low = 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.
1st のように low = max(weights)
とすると
if weight > capacity:
return False
が省略でき、コードが少しシンプルになると思います。
良いと思います |
https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/description/