1572. Matrix Diagonal Sum
Easy
Previous1567. Maximum Length of Subarray With Positive Product ⭐Next1576. Replace All ?'s to Avoid Consecutive Repeating Characters
Last updated
Easy
Last updated
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.
Example 1:
Example 2:
Example 3:
Constraints:
n == mat.length == mat[i].length
1 <= n <= 100
1 <= mat[i][j] <= 100