Given a square matrix
mat
, 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
給予一個方形矩陣
mat
,回傳該矩陣對角線的和。
只包含主對角線上所有元素的和,以及在副對角線卻不在主對角線上所有元素的和。
限制:
n == mat.length == mat[i].length
1 <= n <= 100
1 <= mat[i][j] <= 100
LeetCode
C++