mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
add: leetcode 0846 solution
This commit is contained in:
23
leetcode/0846.Hand-of-Straights/846.Hand of Straights.go
Normal file
23
leetcode/0846.Hand-of-Straights/846.Hand of Straights.go
Normal file
@ -0,0 +1,23 @@
|
||||
package leetcode
|
||||
|
||||
import "sort"
|
||||
|
||||
func isNStraightHand(hand []int, groupSize int) bool {
|
||||
mp := make(map[int]int)
|
||||
for _, v := range hand {
|
||||
mp[v] += 1
|
||||
}
|
||||
sort.Ints(hand)
|
||||
for _, num := range hand {
|
||||
if mp[num] == 0 {
|
||||
continue
|
||||
}
|
||||
for diff := 0; diff < groupSize; diff++ {
|
||||
if mp[num+diff] == 0 {
|
||||
return false
|
||||
}
|
||||
mp[num+diff] -= 1
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
Reference in New Issue
Block a user