Skip to content

Commit 44f1eeb

Browse files
committed
1
1 parent f59526b commit 44f1eeb

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

notes/src/day7/lc383.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ impl Solution {
3232
}
3333
```
3434

35-
## 学习感想
35+
## 学习感想
36+
37+
普通hashmap 的使用

notes/src/day7/lc454.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,34 @@ impl Solution {
7575
res as i32
7676
}
7777
}
78+
```
79+
80+
81+
82+
83+
84+
```rust
85+
struct Solution {}
86+
87+
impl Solution {
88+
pub fn four_sum_count(nums1: Vec<i32>, nums2: Vec<i32>, nums3: Vec<i32>, nums4: Vec<i32>) -> i32 {
89+
use std::collections::HashMap;
90+
let mut map: HashMap<i32, usize> = HashMap::new();
91+
for a in nums1 {
92+
for &b in nums2.iter() {
93+
map.entry(a + b)
94+
.and_modify(|x| *x += 1usize)
95+
.or_insert(1usize);
96+
}
97+
}
98+
let mut res: usize = 0usize;
99+
for c in nums3 {
100+
for &d in nums4.iter() {
101+
map.entry(0i32 - c - d)
102+
.and_modify(|&mut x| res += x);
103+
}
104+
}
105+
res as i32
106+
}
107+
}
78108
```

0 commit comments

Comments
 (0)