← 返回 google 的题目列表Subarray Sum Equals K
类型:online_judge
Given an array of integers nums and an integer k, return the total number of continuous subarrays whose sum equals to k.
Input Description:
An integer array nums with a length in the range [1, 200,000], where each element nums[i] is an integer within the range [-1,000,000, 1,000,000].
An integer k, within the range [-10^7, 10^7].
Output Description:
An integer representing the total number of continuous subarrays that sum to k.
Sample Input:
[1, 1, 1], 2
Sample Output:
2
Notes:
In the sample, there are two subarrays that sum to 2: [1, 1] and [1, 1].
Example
Input
[1, 1, 1]
2