-
Notifications
You must be signed in to change notification settings - Fork 0
Capacity to ship packages within d days #27
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: arai60
Are you sure you want to change the base?
Conversation
nodchip
left a comment
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 shipWithinDays(self, weights: List[int], days: int) -> int: | ||
| invalid_capacity = 0 | ||
| valid_capacity = sum(weights) | ||
| while invalid_capacity < valid_capacity: |
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.
最後に invalid_capacity == valid_capacity となる点が気になりました。
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.
そうなんですよね...なんだかそこの違和感がすごくてphase2, 3では名前を変えました。
if self._is_possible(weights, days, mid_capacity):
valid_capacity = mid_capacityここのところは名が体を表している感じがしますが,
else:
invalid_capacity = mid_capacity + 1のところはmid_capacityのところは確かにinvalidなんですが, +1したものもinvalidとは限らないので少しおかしなことになってしまったなと思います。
こう書き換えれば名が体を表していることになりますでしょうかね?
while invalid_capacity < valid_capacity - 1:
mid_capacity = (valid_capacity + invalid_capacity) // 2
if self._is_possible(weights, days, mid_capacity):
valid_capacity = mid_capacity
else:
invalid_capacity = mid_capacity
return valid_capacity| current_weight = weight | ||
| else: | ||
| current_weight += weight | ||
| if spent_days > 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.
この if 文は消して、最後に return spent_days <= days としたほうがシンプルになると思います。
| shining-ai: https://github.com/shining-ai/leetcode/pull/44/files | ||
| hayashi-ay: https://github.com/hayashi-ay/leetcode/pull/55/files | ||
| is_possibleだと何がpossibleかわかりにくいのでcanbe_shippedへ変更, valid_capacity,invalid_capacityという命名にしていたが | ||
| low, highぐらいの命名へ, 二分探索はこれぐらいの名前の重さの方が伝わりやすい? |
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.
i < len(array) と書いたら添字であると推測するんですよね。長いほうが分かりやすい訳ではないです。
bisect を関数として切り出すのも一つかもしれません。
| shining-ai: https://github.com/shining-ai/leetcode/pull/44/files | ||
| hayashi-ay: https://github.com/hayashi-ay/leetcode/pull/55/files | ||
| is_possibleだと何がpossibleかわかりにくいのでcanbe_shippedへ変更, valid_capacity,invalid_capacityという命名にしていたが | ||
| low, highぐらいの命名へ, 二分探索はこれぐらいの名前の重さの方が伝わりやすい? |
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.
i < len(array) と書いたら添字であると推測するんですよね。長いほうが分かりやすい訳ではないです。
bisect を関数として切り出すのも一つかもしれません。
問題
1011. Capacity To Ship Packages Within D Days