Skip to content

Commit ff9d9a0

Browse files
authored
Added solution for 2206
1 parent 69c3716 commit ff9d9a0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use std::collections::HashMap;
2+
3+
impl Solution {
4+
// Maintain a hashmap to keep count of each number's occurrence. If count of any number is odd, return false. In the end, return true since that means no number occurred odd number of times
5+
pub fn divide_array(nums: Vec<i32>) -> bool {
6+
7+
let mut map = HashMap::new();
8+
for num in &nums {
9+
let count = map.entry(num).or_insert(0);
10+
*count += 1;
11+
}
12+
13+
for (num, num_instances) in &map {
14+
if num_instances % 2 != 0 {
15+
return false;
16+
}
17+
}
18+
19+
return true;
20+
}
21+
}

0 commit comments

Comments
 (0)