c语言sscanf函数的用法是什么
232
2022-08-26
[leetcode] 560. Subarray Sum Equals K
Description
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 = 2
Output:
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 integer k is [-1e7, 1e7].
分析
题目的意思是:找出一个数组里面连续子数组的和为K的子数组的个数。
用一个map存起来,mp[0]的初始值为1,用于然后mp记录的是前m项的求和,mp[sum-k]如果为1,表明存在一个连续子序列的值为k,这需要找个test case模拟一下就行了。
代码
class Solution {public: int subarraySum(vector 参考文献 LeetCode Subarray Sum Equals K 子数组和为K560. Subarray Sum Equals K
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~