Given a square matrix mat, calculate and return the sum of all elements lying on its primary diagonal and secondary diagonal.
Elements that belong to both diagonals should only be included once in the total sum.
Constraints:
n == mat.length == mat[i].length
n
mat[i][j]
Given a square matrix mat, calculate and return the sum of all elements lying on its primary diagonal and secondary diagonal.
Elements that belong to both diagonals should only be included once in the total sum.
Constraints:
n == mat.length == mat[i].length
n
mat[i][j]