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