human
Solve in Python:
Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.

Example 1:

Input:nums = [1,1,1], k = 2
Output: 2


Note:

The length of the array is in range [1, 20,000].
The range of numbers in the array is [-1000, 1000] and the range of the integer k is [-1e7, 1e7].
 Can you provide a Python code to find the total number of continuous subarrays whose sum equals to k?
assistant
#Here is Python code to find the total number of continuous subarrays whose sum equals to k.

class Solution:
     def subarraySum(self, nums, k):
         """
         :type nums: List[int]
         :type k: int
         :rtype: int
         """
         cum_sum_dict = {}
         cum_sum_dict[0] = 1
         left_sum = 0
         count = 0
         for t in nums:
             left_sum = left_sum + t
             if (left_sum - k) in cum_sum_dict:
                 count = count + cum_sum_dict[left_sum - k]
             if left_sum in cum_sum_dict:
                 cum_sum_dict[left_sum] = cum_sum_dict[left_sum] + 1
             else:
                 cum_sum_dict[left_sum] = 1
         
         return count