LeetCode/go/minimum-difference-between-largest-and-smallest-value-in-three-moves.go
2024-07-03 09:57:36 +02:00

18 lines
254 B
Go

package main
import "slices"
func minDifference(nums []int) int {
if len(nums) <= 4 {
return 0
}
slices.Sort(nums)
diff := nums[len(nums)-1] - nums[0]
for i := 0; i < 4; i++ {
diff = min(diff, nums[len(nums)-4+i]-nums[i])
}
return diff
}