We’re preparing your current view and syncing the latest data.
Given an integer array nums and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.
Example: Input: nums = [1,1,1], k = 2 Output: 2
Explanation: The subarrays [1,1] starting at index 0 and at index 1 both sum up to 2.
An integer array nums, and an integer k.
An integer representing the count of continuous subarrays whose sum equals k.
1 <= nums.length <= 2 * 10^4 -10^4 <= nums[i] <= 10^4 -10^7 <= k <= 10^7
Example 1
Input
nums = [1,1,1], k = 2
Output
2
Explanation
The two subarrays [1,1] starting at indices 0 and 1 sum to 2.