Skip to content

Commit 0a10c28

Browse files
committed
Time: 31 ms (80.95%), Space: 66.8 MB (29.52%) - LeetHub
1 parent f625ceb commit 0a10c28

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public long countInterestingSubarrays(List<Integer> nums, int modulo, int k) {
3+
Map<Integer, Integer> cnt = new HashMap<>();
4+
cnt.put(0, 1);
5+
long res = 0;
6+
int prefix = 0;
7+
for (int num : nums) {
8+
if (num % modulo == k) prefix++;
9+
res += cnt.getOrDefault((prefix - k + modulo) % modulo, 0);
10+
cnt.put(prefix % modulo, cnt.getOrDefault(prefix % modulo, 0) + 1);
11+
}
12+
return res;
13+
}
14+
}

0 commit comments

Comments
 (0)