1572. Matrix Diagonal Sum
On This Page
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