[leetcode]Image Smoother

Posted 阿牧遥

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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

  

以上是关于[leetcode]Image Smoother的主要内容,如果未能解决你的问题,请参考以下文章

[leetcode-661-Image Smoother]

[LeetCode] Image Smoother 图片平滑器

LeetCode 661. Image Smoother (图像平滑)

[leetcode]Image Smoother

[LeetCode] 661. Image Smoother_Easy

leetcode 661. 图片平滑器(Image Smoother)