We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c6cbaba commit f841715Copy full SHA for f841715
scripts/algorithms/H/Hand of Straights/Hand of Straights.rs
@@ -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