Skip to content

Conversation

@SuperHotDogCat
Copy link
Owner

問題

209. Minimum Size Subarray Sum

今回に限り少しpepとgoogle coding styleのwhitespaceの項をまじめに議論してみたいです。
気になるところがあったらレビューお願いいたします。

https://peps.python.org/pep-0008/#other-recommendations
https://google.github.io/styleguide/pyguide.html#36-whitespace

right = 0
min_length = len(nums) + 1
while right < len(prefix_sum):
if target <= prefix_sum[right]-prefix_sum[left]:
Copy link

Choose a reason for hiding this comment

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

PEP 8 で演算子の前後でスペースを開けるかについては、自由度があったかと思いますが、私は空けます。

Copy link
Owner Author

Choose a reason for hiding this comment

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

返信遅れて申し訳ないです。こちらPEPを見ていてて, 話したかったところでもあります。
PEPでは

If operators with different priorities are used, consider adding whitespace around the operators with the lowest priority(ies).

そしてこの規則に従うと

x = x*2 - 1

が正しい書き方だそうです。
とあります。こちらでは<=-は優先順位が異なるので, -を詰めるように書いてみたのですがどうでしょうか, 確かに今まではスペースを開けて書いていたので, 少し違和感がありますが...

Copy link

Choose a reason for hiding this comment

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

Use your own judgment; なんである程度好きにしたらいいと思います。

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。(このdiscordでは他の人のコードを見て判断しようと思います)

Comment on lines +37 to +43
while right < len(nums):
prefix_sum += nums[right]
while prefix_sum >= target:
min_length = min(min_length, right - left + 1)
prefix_sum -= nums[left]
left += 1
right += 1
Copy link

Choose a reason for hiding this comment

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

right は含まないようにするのもありですか。なんか、right += 1 と prefix_sum += nums[right] が分裂しているのがちょっと気になります。

        while right <= len(nums):
            while prefix_sum >= target:
                min_length = min(min_length, right - left)
                prefix_sum -= nums[left]
                left += 1
            prefix_sum += nums[right]
            right += 1

(合っているか知りません。)

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。離れると確かに少し頭を使ってrightとleftの状態を考えてしまうのでそういたします

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