Clean python code


  • 1
    class Solution(object):
        def compress(self, matrix):
            return [
                [i, j, num]
                for i, row in enumerate(matrix)
                for j, num in enumerate(row) if num
            ]
    
        def multiply(self, A, B):
            (cpA, cpB), r = map(self.compress, (A, B)), [
                [0] * len(B[0]) for i in xrange(len(A))]
    
            [r[rowA].__setitem__(columnB, r[rowA][columnB] + numA * numB)
             for rowA, columnA, numA in cpA
             for rowB, columnB, numB in cpB if columnA == rowB]
    
            return r

Log in to reply
 

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