Image Smoother LeetCode solution in Python
1# Runtime: 1147 ms (Top 25.09%) | Memory: 14.8 MB (Top 29.59%)2class Solution:3def imageSmoother(self, img: List[List[int]]) -> List[List[int]]:4m, n = len(img), len(img[0])56def avg(i, j):7s = squares = 08top, bottom = max(0, i - 1), min(m, i + 2)9left, right = max(0, j - 1), min(n, j + 2)1011for x in range(top, bottom):12for y in range(left, right):13s += img[x][y]14squares += 11516return s // squares1718return [[avg(i, j) for j in range(n)] for i in range(m)]