We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给定一个整数数组和一个整数 k,你需要找到该数组中和为 k 的连续的子数组的个数。
Input:nums = [1,1,1], k = 2 Output: 2
The text was updated successfully, but these errors were encountered:
/** * @param {number[]} nums * @param {number} k * @return {number} */ var subarraySum = function(nums, k) { const cache = new Map(); let prefixSum = 0; let result = 0; cache.set(0, 1); for (let i = 0; i < nums.length; i++) { prefixSum += nums[i] if (cache.has(prefixSum - k)) { result += cache.get(prefixSum - k); } cache.set(prefixSum, (cache.get(prefixSum) || 0) + 1) } return result; };
Sorry, something went wrong.
No branches or pull requests
560. Subarray Sum Equals K
给定一个整数数组和一个整数 k,你需要找到该数组中和为 k 的连续的子数组的个数。
Example
Note
The text was updated successfully, but these errors were encountered: