LeetCode-560. Subarray Sum Equals K
LeetCode-560. Subarray Sum Equals K
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 = 2Output: 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 integerkis [-1e7, 1e7].
题解:
最初想到用滑动窗口来做,发现测试用例有负数,没法正常滑动窗口,使用map存储0-i的sum,然后找到钱面和为sum-k的个数,相加。
class Solution {public: int subarraySum(vector
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~