Skip to content

Commit a73335d

Browse files
authored
Update README_EN.md
1 parent 2c95b29 commit a73335d

File tree

1 file changed

+29
-0
lines changed
  • solution/2800-2899/2845.Count of Interesting Subarrays

1 file changed

+29
-0
lines changed

solution/2800-2899/2845.Count of Interesting Subarrays/README_EN.md

+29
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,35 @@ function countInterestingSubarrays(nums: number[], modulo: number, k: number): n
206206
}
207207
```
208208

209+
#### Rust
210+
211+
```rust
212+
use std::collections::HashMap;
213+
214+
impl Solution {
215+
pub fn count_interesting_subarrays(nums: Vec<i32>, modulo: i32, k: i32) -> i64 {
216+
let mut arr: Vec<i32> = nums
217+
.iter()
218+
.map(|&x| if x % modulo == k { 1 } else { 0 })
219+
.collect();
220+
let mut cnt: HashMap<i32, i64> = HashMap::new();
221+
cnt.insert(0, 1);
222+
223+
let mut ans: i64 = 0;
224+
let mut s: i32 = 0;
225+
226+
for x in arr {
227+
s += x;
228+
let key = (s - k).rem_euclid(modulo);
229+
ans += *cnt.get(&key).unwrap_or(&0);
230+
*cnt.entry(s % modulo).or_insert(0) += 1;
231+
}
232+
233+
ans
234+
}
235+
}
236+
```
237+
209238
<!-- tabs:end -->
210239

211240
<!-- solution:end -->

0 commit comments

Comments
 (0)