Skip to content

Commit f841715

Browse files
committed
Runtime: 10 ms (Top 100.0%) | Memory: 2.20 MB (Top 92.31%)
1 parent c6cbaba commit f841715

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Runtime: 10 ms (Top 100.0%) | Memory: 2.20 MB (Top 92.31%)
2+
3+
impl Solution {
4+
pub fn is_n_straight_hand(mut hand: Vec<i32>, group_size: i32) -> bool {
5+
use std::collections::HashMap;
6+
hand.sort();
7+
let mut freq = hand.iter().copied().fold(HashMap::new(), |mut acc, x| {
8+
*acc.entry(x).or_insert(0) += 1;
9+
acc
10+
});
11+
for h in hand {
12+
if *freq.get(&h).unwrap() == 0 {
13+
continue;
14+
}
15+
for i in 0..group_size {
16+
if freq.contains_key(&(h + i)) && *freq.get(&(h + i)).unwrap() > 0 {
17+
*freq.get_mut(&(h + i)).unwrap() -= 1;
18+
} else {
19+
return false;
20+
}
21+
}
22+
}
23+
true
24+
}
25+
}

0 commit comments

Comments
 (0)