add: leetcode 0846 solution

This commit is contained in:
tphyhFighting
2021-12-31 18:01:48 +08:00
parent 1a959a2ace
commit fe6a721e36

View 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
}