This commit is contained in:
kkunkka
2025-04-26 15:09:19 +08:00
parent 12d32a4342
commit fdcfae8c9a

View File

@@ -0,0 +1,23 @@
package com.dota.slidingWindow._2845;
import java.util.HashMap;
import java.util.List;
class Solution {
public long countInterestingSubarrays(List<Integer> nums, int modulo, int k) {
long res = 0;
int cnt = 0;
var map = new HashMap<Integer, Integer>();
map.put(0, 1);
for (Integer num : nums) {
if (num % modulo == k) {
cnt++;
}
if (cnt >= k) {
res += map.getOrDefault((cnt - k) % modulo, 0);
}
map.put(cnt%modulo, map.getOrDefault(cnt%modulo, 0) + 1);
}
return res;
}
}