码迷,mamicode.com
首页 > 其他好文 > 详细

[leetcode]Image Smoother

时间:2020-02-06 11:04:34      阅读:63      评论:0      收藏:0      [点我收藏+]

标签:smo   res   def   smooth   for   poi   ESS   highlight   The   

简单题

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

标签:smo   res   def   smooth   for   poi   ESS   highlight   The   

原文地址:https://www.cnblogs.com/lautsie/p/12267668.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!