首页 > 其他 > 详细

[leetcode]Image Smoother

时间:2020-02-06 10:25:28      阅读:75      评论:0      收藏:0      [点我收藏+]

简单题

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!