Skip to content

Conversation

@SuperHotDogCat
Copy link
Owner

Copy link

@nodchip nodchip left a 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:
Copy link

Choose a reason for hiding this comment

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

最後に invalid_capacity == valid_capacity となる点が気になりました。

Copy link
Owner Author

@SuperHotDogCat SuperHotDogCat Jun 7, 2024

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:
Copy link

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ぐらいの命名へ, 二分探索はこれぐらいの名前の重さの方が伝わりやすい?
Copy link

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ぐらいの命名へ, 二分探索はこれぐらいの名前の重さの方が伝わりやすい?
Copy link

Choose a reason for hiding this comment

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

i < len(array) と書いたら添字であると推測するんですよね。長いほうが分かりやすい訳ではないです。

bisect を関数として切り出すのも一つかもしれません。

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.

4 participants