Given an n x n square matrix matrix, return the sum of the elements on both diagonals.
The primary diagonal runs from top-left to bottom-right. The secondary diagonal runs from top-right to bottom-left.
If the matrix has an odd size, the center element belongs to both diagonals — count it only once.
matrix = [[1,2,3],[4,5,6],[7,8,9]]25matrix = [[1,2],[3,4]]10matrix = [[5]]5n == matrix.length == matrix[i].length1 <= n <= 100-1000 <= matrix[i][j] <= 1000Run your code to see results
Use Cmd+Enter to run