/*
* @lc app=leetcode.cn id=908 lang=typescript
*
* [908] 最小差值 I
*/
// @lc code=start
function smallestRangeI(nums: number[], k: number): number {}
// @lc code=end
function smallestRangeI(nums: number[], k: number): number {
let max = -Infinity,
min = Infinity
for (let num of nums) {
max = Math.max(max, num)
min = Math.min(min, num)
}
return Math.max(0, max - k - (min + k))
}
test.each([
{ input: { nums: [1], k: 0 }, output: 0 },
{ input: { nums: [0, 10], k: 2 }, output: 6 },
{ input: { nums: [1, 3, 6], k: 3 }, output: 0 },
])('input: nums = $input.nums, k = $input.k', ({ input: { nums, k }, output }) => {
expect(smallestRangeI(nums, k)).toEqual(output)
})