mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-14 09:59:41 +01:00
19 lines
254 B
Go
19 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
|
||
|
}
|