mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
go: add «1509. Minimum Difference Between Largest and Smallest Value in Three Moves»
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
d89dbdcac2
commit
bcabf01c65
1 changed files with 18 additions and 0 deletions
|
@ -0,0 +1,18 @@
|
||||||
|
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
|
||||||
|
}
|
Loading…
Reference in a new issue