1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
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
}