File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var countInterestingSubarrays = function(nums, modulo, k) {
2+
let cnt = new Map();
3+
cnt.set(0, 1);
4+
let prefix = 0, res = 0;
5+
for (let num of nums) {
6+
prefix += (num % modulo === k) ? 1 : 0;
7+
let target = (prefix - k + modulo) % modulo;
8+
res += cnt.get(target) || 0;
9+
cnt.set(prefix % modulo, (cnt.get(prefix % modulo) || 0) + 1);
10+
}
11+
return res;
12+
};

0 commit comments

Comments
 (0)