This commit is contained in:
2026-01-26 18:47:01 +08:00
parent b08a6b9776
commit 06508ed118
2 changed files with 40 additions and 0 deletions

25
26/01/go/1200.go Normal file
View File

@@ -0,0 +1,25 @@
package A
import "sort"
func minimumAbsDifference(arr []int) [][]int {
sort.Slice(arr, func(i, j int) bool {
return arr[i] < arr[j]
})
ans := [][]int{}
n := len(arr)
minDiff := arr[1] - arr[0]
for i := 1; i < n; i++ {
temp := arr[i] - arr[i-1]
if minDiff > temp {
minDiff = temp
}
}
for i := 1; i < n; i++ {
temp := arr[i] - arr[i-1]
if temp == minDiff {
ans = append(ans, []int{arr[i-1], arr[i]})
}
}
return ans
}

15
test.go Normal file
View File

@@ -0,0 +1,15 @@
package main
import (
"fmt"
"sort"
)
func sorts(arr []int) {
sort.Ints(arr)
fmt.Println(arr)
}
func main() {
sorts([]int{3, 8, -10, 23, 19, -4, -14, 27})
}