mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-07 09:54:57 +08:00
add: leetcode 1296 solution
This commit is contained in:
@ -0,0 +1,23 @@
|
|||||||
|
package leetcode
|
||||||
|
|
||||||
|
import "sort"
|
||||||
|
|
||||||
|
func isPossibleDivide(nums []int, k int) bool {
|
||||||
|
mp := make(map[int]int)
|
||||||
|
for _, v := range nums {
|
||||||
|
mp[v] += 1
|
||||||
|
}
|
||||||
|
sort.Ints(nums)
|
||||||
|
for _, num := range nums {
|
||||||
|
if mp[num] == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for diff := 0; diff < k; diff++ {
|
||||||
|
if mp[num+diff] == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
mp[num+diff] -= 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
Reference in New Issue
Block a user