Skip to content

Solved Arai60/560. Subarray Sum Equals K#16

Open
Satorien wants to merge 1 commit into
mainfrom
solve/arai60_560
Open

Solved Arai60/560. Subarray Sum Equals K#16
Satorien wants to merge 1 commit into
mainfrom
solve/arai60_560

Conversation

@Satorien
Copy link
Copy Markdown
Owner

return count
```

- `if cumulative_sum == k:` の代わりにHashMapに0: 1を入れておく方法もあるが、自然言語的には今の方が違和感なく出来ている気がするのでこのままにする
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

駅の標高差の話だと思うと、代入でもすんなりくるかもしれません。
https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.bp0g0ai41eln

あと、なんとなく考え方の章あたりを見ておいてもらえると嬉しいです。

prefix_sum_to_count: Dict[int, int] = defaultdict(int)
for prefix_sum in accumulate(nums):
if prefix_sum == k:
count += 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

私は、prefix_sum_to_count[0] = 1としたほうがわかりやすいと思いましたが、趣味ですかね。

- `if cumulative_sum == k:` の代わりにHashMapに0: 1を入れておく方法もあるが、自然言語的には今の方が違和感なく出来ている気がするのでこのままにする
- パフォーマンス最適化する目的なら変えるべき
- 今回はかなり悩んでしまう時間が長かったので、うだうだ悩む癖をやめたい
- 思考整理→実装のステップで思考整理から詰まっている場合は諦めた方が良い
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

こちら参考になるかもしれません
plushn/SWE-Arai60#15 (comment)

## Step 1. Initial Solution

- 連続する配列の一部の和がある値となるような配列の切り取り方の総数
- 二重ループで和が一致した時にcountしていく方法を最初に思い付いたがTLE
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

fuga-98/arai60#45 (comment)
こちらのコメントを参照されることをお勧めします。

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