Участник:Vovaf709/matrix

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/range-sum-query-2d-immutable/

class NumMatrix:
 
    def __init__(self, matrix: List[List[int]]):
        self.matrix = matrix
 
    def sumRegion(self, row1: int, col1: int, row2: int, col2: int) -> int:
        summa = 0
        for i in range(row1, row2+1):
            for j in range(col1, col2+1):
                summa+=self.matrix[i][j]
        return summa
 
 
# Your NumMatrix object will be instantiated and called as such:
# obj = NumMatrix(matrix)
# param_1 = obj.sumRegion(row1,col1,row2,col2)