-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.py
32 lines (30 loc) · 1.07 KB
/
solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Solution(object):
def imageSmoother(self, M):
"""
:type M: List[List[int]]
:rtype: List[List[int]]
"""
res = []
for i in range(0, len(M)):
row = []
for j in range(0, len(M[0])):
points = [M[i][j]]
if j >= 1:
points.append(M[i][j - 1])
if j + 1 < len(M[0]):
points.append(M[i][j + 1])
if i >= 1:
points.append(M[i - 1][j])
if j >= 1:
points.append(M[i - 1][j - 1])
if j + 1 < len(M[0]):
points.append(M[i - 1][j + 1])
if i + 1 < len(M):
points.append(M[i + 1][j])
if j >= 1:
points.append(M[i + 1][j - 1])
if j + 1 < len(M[0]):
points.append(M[i + 1][j + 1])
row.append(sum(points) / len(points))
res.append(row)
return res