Hand of Straights LeetCode solution in Rust

1
impl Solution {
2
pub fn is_n_straight_hand(mut hand: Vec<i32>, group_size: i32) -> bool {
3
use std::collections::HashMap;
4
hand.sort();
5
let mut freq = hand.iter().copied().fold(HashMap::new(), |mut acc, x| {
6
*acc.entry(x).or_insert(0) += 1;
7
acc
8
});
9
for h in hand {
10
if *freq.get(&h).unwrap() == 0 {
11
continue;
12
}
13
for i in 0..group_size {
14
if freq.contains_key(&(h + i)) && *freq.get(&(h + i)).unwrap() > 0 {
15
*freq.get_mut(&(h + i)).unwrap() -= 1;
16
} else {
17
return false;
18
}
19
}
20
}
21
true
22
}
23
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0