Given an array of integers and an integer k, your task is to find the total number of continuous subarrays whose sum equals to k.
nums
and an integer k
.k
.nums
is empty.Input: nums = [1, 1, 1], k = 2
Output: 2
Explanation: There are two continuous subarrays [1,1] that sum up to 2.
Below is some language-agnostic starter code to help you begin your solution.
function subarraySum(nums, k) {
// returns the number of continuous subarrays whose sum equals k
}
Happy coding! Consider the innovative use of hashmaps as a tool that some of the greatest developers have mastered over the years.