Python solution, one line per function.


  • 0
    G
    class NumMatrix(object):
    
        def __init__(self, matrix):
            self.matrix = matrix
    
        def update(self, row, col, val):
            self.matrix[row][col]=val
    
        def sumRegion(self, row1, col1, row2, col2):
            return reduce(lambda s, row: s+sum(row[col1:col2+1]),self.matrix[row1:row2+1],0)

Log in to reply
 

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