Matrix Diagonal Sum
Easy
Arrays
Array
Matrix
Given an n×n matrix, return the sum of both diagonals (count center once for odd n).
Constraints
1 ≤ n ≤ 100
Examples
Example 1:
Input: 1 2 3
4 5 6
7 8 9
Output: 25
Example 2:
Input: 1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
Output: 8
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console