Skip to content

Conversation

@syoshida20
Copy link
Owner

@syoshida20 syoshida20 commented May 6, 2025

問題URL

問題文

Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k.
A subarray is a contiguous non-empty sequence of elements within an array.

Example 1:

  • Input: nums = [1,1,1], k = 2
  • Output: 2

Example 2:

  • Input: nums = [1,2,3], k = 3
  • Output: 2

Constraints:

  • 1 <= nums.length <= 2 * 104
  • -1000 <= nums[i] <= 1000
  • -107 <= k <= 107

@syoshida20 syoshida20 marked this pull request as ready for review May 11, 2025 01:53
}
}
return count
};

Choose a reason for hiding this comment

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

特に問題ないと思いました。
強いていうならcumSumをcumulativeSumとしたい人もいる気がします。

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。

cumSumがcumulativeSumであることは、確かに自明ではないですね。

```javascript
const subarraySum = function(nums, k) {
const cumSumToCount = new Map()
cumSumToCount.set(0, 1)
Copy link

Choose a reason for hiding this comment

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

この1に違和感がなければ問題ないかと思います。

Copy link
Owner Author

@syoshida20 syoshida20 May 21, 2025

Choose a reason for hiding this comment

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

はい、違和感は無いです。

先頭の要素を含む部分列を含めるために必要です!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants