1572. Matrix Diagonal Sum

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1572

class Solution:
    def diagonalSum(self, mat: List[List[int]]) -> int:
        res = 0
        n = len(mat)
        for i, row in enumerate(mat):
            j = n - i - 1
            res += row[i] + (0 if j == i else row[j])
        return res