连续子数组的和
1.前缀法
class Solution:
def checkSubarraySum(self, nums: List[int], k: int) -> bool:
pre_sum = {0 : -1}
tmp = 0
l = len(nums)
if l < 2:
return False
for i in range(l):
tmp += nums[i]
leave = tmp%k
if leave in pre_sum:
if i - pre_sum[leave] >= 2:
return True
else:
pre_sum[leave] = i
return False