Matrix Diagonal Sum

Given a square matrix, return the sum of the matrix diagonals. Only include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal.

Constraints

  • n == mat.length == mat[i].length
  • 1 <= n <= 100
  • 1 <= mat[i][j] <= 100
Saving… · 2 lines
class Solution:
def matrixDiagonalSum(self, mat: List[List[int]]) -> int:
Console

Click Run to execute sample tests.