简单题

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

  

相关文章:

  • 2021-07-04
  • 2021-12-04
  • 2021-09-25
  • 2022-02-03
  • 2022-02-20
  • 2021-07-21
猜你喜欢
  • 2021-07-14
  • 2022-12-23
  • 2022-01-11
  • 2021-08-01
  • 2022-12-23
  • 2021-08-26
  • 2022-12-23
相关资源
相似解决方案