[leetcode]Image Smoother
简单题
class Solution:
def imageSmoother(self, M: List[List[int]]) -> List[List[int]]:
m = len(M)
n = len(M[0])
result = [[0] * n for _ in range(m)]
for i in range(m):
for j in range(n):
# process point (i, j)
total = 0
cnt = 0
for x in [i-1, i, i+1]:
for y in [j-1, j, j+1]:
if x < 0 or y < 0 or x >= m or y >= n:
continue
total += M[x][y]
cnt += 1
result[i][j] = int(total / cnt)
return result

浙公网安备 33010602011771号