Solved Arai60/560. Subarray Sum Equals K#16
Open
Satorien wants to merge 1 commit into
Open
Conversation
oda
reviewed
May 16, 2025
| return count | ||
| ``` | ||
|
|
||
| - `if cumulative_sum == k:` の代わりにHashMapに0: 1を入れておく方法もあるが、自然言語的には今の方が違和感なく出来ている気がするのでこのままにする |
There was a problem hiding this comment.
駅の標高差の話だと思うと、代入でもすんなりくるかもしれません。
https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.bp0g0ai41eln
あと、なんとなく考え方の章あたりを見ておいてもらえると嬉しいです。
fuga-98
reviewed
May 16, 2025
| prefix_sum_to_count: Dict[int, int] = defaultdict(int) | ||
| for prefix_sum in accumulate(nums): | ||
| if prefix_sum == k: | ||
| count += 1 |
There was a problem hiding this comment.
私は、prefix_sum_to_count[0] = 1としたほうがわかりやすいと思いましたが、趣味ですかね。
fuga-98
reviewed
May 16, 2025
| - `if cumulative_sum == k:` の代わりにHashMapに0: 1を入れておく方法もあるが、自然言語的には今の方が違和感なく出来ている気がするのでこのままにする | ||
| - パフォーマンス最適化する目的なら変えるべき | ||
| - 今回はかなり悩んでしまう時間が長かったので、うだうだ悩む癖をやめたい | ||
| - 思考整理→実装のステップで思考整理から詰まっている場合は諦めた方が良い |
There was a problem hiding this comment.
こちら参考になるかもしれません
plushn/SWE-Arai60#15 (comment)
nodchip
reviewed
May 17, 2025
| ## Step 1. Initial Solution | ||
|
|
||
| - 連続する配列の一部の和がある値となるような配列の切り取り方の総数 | ||
| - 二重ループで和が一致した時にcountしていく方法を最初に思い付いたがTLE |
There was a problem hiding this comment.
fuga-98/arai60#45 (comment)
こちらのコメントを参照されることをお勧めします。
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.
問題文:https://leetcode.com/problems/subarray-sum-equals-k/description/