523 Continuous Subarray Sum
Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple of k, that is, sums up to n*k where n is also an integer.
Example 1:
Example 2:
Note:
The length of the array won't exceed 10,000.
You may assume the sum of all the numbers is in the range of a signed 32-bit integer.
这题的难点是处理k = 0的情况。因为这时候%k的话会抛异常。处理方法是,当k==0时,我们存preSum到hm里,以后再看到这个preSum的时候,证明我们已经找到一段subarray that add up to 0.(这步完全就是138)如果k != 0,我们存余数。T:O(n), S:O(n)
Last updated