Skip to content

560. Subarray Sum Equals K#16

Open
TakayaShirai wants to merge 1 commit intomainfrom
560_subarray_sum_equals_k
Open

560. Subarray Sum Equals K#16
TakayaShirai wants to merge 1 commit intomainfrom
560_subarray_sum_equals_k

Conversation

@TakayaShirai
Copy link
Copy Markdown
Owner

@TakayaShirai TakayaShirai self-assigned this Jan 12, 2026
Comment on lines +84 to +85
var cumulativeSum = 0;
var sumToCount = <int, int>{cumulativeSum: 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.

これ、とても良いと思いました。

「いまの累積和は0です」「その累積和を1回見ました」という意図が伝わってきました。

for (var num in nums) {
cumulativeSum += num;

final target = cumulativeSum - k;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

k も問題で与えられた target なわけで、ここで改めて出てきた target とは?とわずかに混乱しました。個人的には、どこかのPRで見た complement が結構しっくり来ました。ご参考まで

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

いつもレビューありがとうございます!

確かに target だと何も具体的な役割を伝えられていないですね…。complementの方が私もしっくりきます、ありがとうございます。

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.

2 participants