1572. Matrix Diagonal Sum

Updated: 2024-03-12
1 min read
[]

On This Page

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