This commit is contained in:
2026-01-25 18:04:39 +08:00
parent 124c7332d8
commit b08a6b9776

21
26/01/go/1984.go Normal file
View File

@@ -0,0 +1,21 @@
package A
import (
"sort"
)
func minimumDifference(nums []int, k int) int {
if k == 1 {
return 0
}
n := len(nums)
sort.Ints(nums)
ans := nums[n-1] - nums[0]
for i := 0; i+k-1 < n; i++ {
temp := nums[i+k-1] - nums[i]
if ans > temp {
ans = temp
}
}
return ans
}