---
# System prepended metadata

title: 908. Smallest Range I
tags: [leetcode]

---

# 908. Smallest Range I
#### Difficulty: Easy
link: https://leetcode.com/problems/smallest-range-i/

### 1. Math  
#### $O(n)$ runtime, $O(1)$ space

這題挺簡單的，因為A的每個元素能自由增加-K~K，讓最大和最小的元素都往中間靠近K，如果會超過就讓它距離為0。

##### python
```python=
class Solution:
    def smallestRangeI(self, A: List[int], K: int) -> int:
        return max(max(A)-min(A)-2*K, 0)
```

<font color="#00AB5F ">Accepted</font>  
Runtime: **108 ms**, faster than **82.13%** of Python3 online submissions for Smallest Range I.  
Memory Usage: **15.4 MB**, less than **43.24%** of Python3 online submissions for Smallest Range I.

###### tags: `leetcode`