Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k.
A subarray is a contiguous non-empty sequence of elements within an array.
prefix sum => n^2 algorithm.
Constraints:
- 1 <= nums.length <= 2 * 104
- -1000 <= nums[i] <= 1000
- -107 <= k <= 107
Nope I cannot. The time complexity is too high. So if the array's sum equal to k. we just know whose pj - pi == k. We can use a hashset. pi = pj - k. We just turn prefix sum into the numebr of intervals equal to the prefix sum we want.
Yes! AC!