51. Subarrays with Target Sum
Medium
Given an array of integers and a target, return how many contiguous subarrays have sum equal to the target. Subarrays at different positions count separately.
Example 1
Input: nums = [1,-1,2,1], alvo = 2
Output: 3
Example 2
Input: nums = [0,0,0], alvo = 0
Output: 6
Constraints
- 0 <= nums.length <= 10000
- -10000 <= nums[i], alvo <= 10000
ArraysHash mapPrefix sums
Saved in this browser
Caso 1
nums =
[1,-1,2,1]
alvo =
2
Expected =
3
Caso 2
nums =
[0,0,0]
alvo =
0
Expected =
6
Run checks these 2 cases. Submit runs all 6, including hidden ones.