Capacity to ship packages within d days#27
Open
SuperHotDogCat wants to merge 4 commits intoarai60from
Open
Conversation
nodchip
approved these changes
Jun 7, 2024
| 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.
最後に invalid_capacity == valid_capacity となる点が気になりました。
Owner
Author
There was a problem hiding this comment.
そうなんですよね...なんだかそこの違和感がすごくて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.
この if 文は消して、最後に return spent_days <= days としたほうがシンプルになると思います。
oda
reviewed
Jun 7, 2024
| 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.
i < len(array) と書いたら添字であると推測するんですよね。長いほうが分かりやすい訳ではないです。
bisect を関数として切り出すのも一つかもしれません。
oda
reviewed
Jun 7, 2024
| 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.
i < len(array) と書いたら添字であると推測するんですよね。長いほうが分かりやすい訳ではないです。
bisect を関数として切り出すのも一つかもしれません。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題
1011. Capacity To Ship Packages Within D Days