Skip to content

Commit e110521

Browse files
authored
Create 1572-matrix-diagonal-sum.kt
1 parent 160c850 commit e110521

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

kotlin/1572-matrix-diagonal-sum.kt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
fun diagonalSum(mat: Array<IntArray>): Int {
3+
val n = mat.lastIndex
4+
5+
var sum = 0
6+
for (i in 0..n) {
7+
sum += mat[i][i] + mat[n - i][i]
8+
}
9+
10+
if (n % 2 == 0)
11+
sum -= mat[n/2][n/2]
12+
13+
return sum
14+
}
15+
}

0 commit comments

Comments
 (0)