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.
Thoughts:
Use map:
Query whether there is a index with value equal to modulo preSum and whether its distance from current i is > 1
Use end<modulo preSum: index> to record the modulo preSum value
Use only set + add delay
Python
Last updated
Was this helpful?