Skip to content

Commit 581df84

Browse files
committed
Runtime: 0 ms (Top 100.0%) | Memory: 2.10 MB (Top 100.0%)
1 parent 612db5a commit 581df84

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Runtime: 0 ms (Top 100.0%) | Memory: 2.10 MB (Top 100.0%)
2+
3+
use std::collections::HashMap;
4+
5+
impl Solution {
6+
pub fn number_of_pairs(nums: Vec<i32>) -> Vec<i32> {
7+
let mut mapped_nums = HashMap::new();
8+
9+
nums.iter().for_each(|&x| {
10+
mapped_nums
11+
.entry(x)
12+
.and_modify(|value| *value += 1)
13+
.or_insert(1);
14+
});
15+
16+
mapped_nums
17+
.values()
18+
.map(|&value| (value / 2, value % 2))
19+
.fold(vec![0, 0], |mut acc, value| {
20+
acc[0] += value.0;
21+
acc[1] += value.1;
22+
acc
23+
})
24+
}
25+
}
26+

0 commit comments

Comments
 (0)