Conversation
| right = 0 | ||
| min_length = len(nums) + 1 | ||
| while right < len(prefix_sum): | ||
| if target <= prefix_sum[right]-prefix_sum[left]: |
There was a problem hiding this comment.
PEP 8 で演算子の前後でスペースを開けるかについては、自由度があったかと思いますが、私は空けます。
There was a problem hiding this comment.
返信遅れて申し訳ないです。こちらPEPを見ていてて, 話したかったところでもあります。
PEPでは
If operators with different priorities are used, consider adding whitespace around the operators with the lowest priority(ies).
そしてこの規則に従うと
x = x*2 - 1
が正しい書き方だそうです。
とあります。こちらでは<=と-は優先順位が異なるので, -を詰めるように書いてみたのですがどうでしょうか, 確かに今まではスペースを開けて書いていたので, 少し違和感がありますが...
There was a problem hiding this comment.
Use your own judgment; なんである程度好きにしたらいいと思います。
There was a problem hiding this comment.
ありがとうございます。(このdiscordでは他の人のコードを見て判断しようと思います)
| 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 |
There was a problem hiding this comment.
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(合っているか知りません。)
There was a problem hiding this comment.
ありがとうございます。離れると確かに少し頭を使ってrightとleftの状態を考えてしまうのでそういたします
問題
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