-
Notifications
You must be signed in to change notification settings - Fork 0
Minimum size subarray sum #31
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
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP 8 で演算子の前後でスペースを開けるかについては、自由度があったかと思いますが、私は空けます。
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.
返信遅れて申し訳ないです。こちら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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use your own judgment; なんである程度好きにしたらいいと思います。
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.
ありがとうございます。(この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.
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(合っているか知りません。)
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.
ありがとうございます。離れると確かに少し頭を使って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