Python AC Solution


  • 1
    A
    class Solution(object):
        def imageSmoother(self, M):
            """
            :type M: List[List[int]]
            :rtype: List[List[int]]
            """
            if not M or not M[0]:
                return
            m = len(M)
            n = len(M[0])
            self.N = []
            for i in xrange(m):
                for j in xrange(n):
                    self.update(M, m, n, i, j)
            return zip(*([iter(self.N)] * n))
        def update(self, M, m, n, i, j):
            x = y = 0
            for p in xrange(max(i - 1, 0), min(i + 2, m)):
                for q in xrange(max(j - 1, 0), min(j + 2, n)):
                    x += M[p][q]
                    y += 1
            self.N.append(x/y)

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.