Loading...
Given an array of integers nums and an integer k, return the total number of contiguous, non-empty subarrays whose elements sum to exactly k.
A subarray is a contiguous, non-empty sequence of elements within the array. Two subarrays are considered different if they start or end at different indices, even when they contain equal values.
Input: nums = [1,1,1], k = 2
Output: 2
Explanation: The subarrays nums[0..1] and nums[1..2] each sum to 2.
Input: nums = [1,2,3], k = 3
Output: 2
Explanation: The subarray nums[0..1] sums to 3, and the single element nums[2] sums to 3.
nums.length ≤2×104nums[i] ≤1000k ≤107Click "Run" to test with sample cases or "Submit" to run all tests.