← 返回 apple 的题目列表Count Continuous Subarrays with Sum Exactly K
类型:online_judge
Problem
Given an integer array nums (may contain negative numbers and zeros) and an integer k, compute the number of contiguous subarrays whose sum is exactly k.
Input (stdin)
Line 1: integer n, the length of the array.
Line 2: n integers, the array nums.
Line 3: integer k.
Output (stdout)
Print one integer: the count of contiguous subarrays with sum exactly k.
Constraints
1 <= n <= 2 * 10^5
-10^9 <= nums[i] <= 10^9
-10^9 <= k <= 10^9
Example
Input:
4
1 2 3 -2
3
Output:
2
Explanation: subarrays are [1,2] and [3].
Example
Input
4
1 2 3 -2
3
Output
2