func smallestRangeI(A []int, K int) int {
min := A[0]
max := A[0]
for i := range A {
v := A[i]
if min > v {
min = v
}
if max < v {
max = v
}
}
if max-K <= min+K {
return 0
} else {
return max - min - 2*K
}
}
网友评论