File tree
Expand file treeCollapse file tree1 file changed
+12
-0
lines changed Expand file treeCollapse file tree1 file changed
+12
-0
lines changed Original file line number | Diff line number | Diff line change |
---|
|
| 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 | +}; |
You can’t perform that action at this time.
0 commit comments