Given an integer array nums and an integer k, return the total number of subarrays whose sum equals k.
A subarray is a contiguous non-empty sequence of elements within an array.
Input: nums = [1, 1, 1], k = 2 Output: 2 Explanation: The subarrays [1, 1] (indices 0-1) and [1, 1] (indices 1-2) each sum to 2.
Input: nums = [1, 2, 3], k = 3 Output: 2 Explanation: The subarrays [3] (index 2) and [1, 2] (indices 0-1) each sum to 3.
Input: nums = [1], k = 1 Output: 1 Explanation: The only subarray [1] sums to 1.
nums = [1, 1, 1], k = 2