写的乱乱的
就一些prefix sum搞来搞去
明天乖乖上班
哀哀哀
def minSubarray(self, nums: List[int], p: int) -> int:
res = 0
for num in nums:
res += num
res = res%p
cur_sum = 0
mp = {}
mp[0] = -1
ans = 10**6
for i, num in enumerate(nums):
cur_sum += num
cur_res = cur_sum%p
mp[cur_res] = i
target_res = (cur_res-res+p)%p
if target_res in mp:
ans = min(ans, i-mp[target_res])
if ans==10**6 or ans==len(nums):
return -1
else:
return ans