-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy path0661-image-smoother.py
More file actions
26 lines (21 loc) · 765 Bytes
/
0661-image-smoother.py
File metadata and controls
26 lines (21 loc) · 765 Bytes
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
# time complexity: O(m*n)
# space complexity: O(m*n)
from typing import List
class Solution:
def imageSmoother(self, img: List[List[int]]) -> List[List[int]]:
m = len(img)
n = len(img[0])
smoothImg = [[0] * n for _ in range(m)]
for i in range(m):
for j in range(n):
sum = 0
count = 0
for x in (i - 1, i, i + 1):
for y in (j - 1, j, j + 1):
if 0 <= x < m and 0 <= y < n:
sum += img[x][y]
count += 1
smoothImg[i][j] = sum // count
return smoothImg
img = [[100, 200, 100], [200, 50, 200], [100, 200, 100]]
print(Solution().imageSmoother(img))