← 返回 bytedance 的题目列表Count Subarrays Whose Sum Equals K
类型:online_judge
Problem: Count Subarrays Whose Sum Equals k
Given an integer array nums and an integer k, return the number of non-empty contiguous subarrays whose sum is exactly k.
A subarray must consist of consecutive elements in the original array.
Input Format
First line: two integers n and k
Second line: n integers representing nums
Output Format
Print one integer: the number of non-empty contiguous subarrays with sum k.
Example 1
Input:
3 2
1 1 1
Output:
2
Example 2
Input:
3 3
1 2 3
Output:
2
Constraints
1 <= n <= 2 * 10^5
-1000 <= nums[i] <= 1000
-10^9 <= k <= 10^9
Example
Input
3 2
1 1 1
Output
2