Skip to content

Commit 67a6402

Browse files
Merge pull request neetcode-gh#3464 from Tetsuya3850/patch-11
2 parents 5d638cd + e04f841 commit 67a6402

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

java/1572-matrix-diagonal-sum.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int diagonalSum(int[][] mat) {
3+
int res = 0;
4+
int n = mat.length;
5+
6+
for (int i = 0; i < n; i++) {
7+
res += mat[i][i];
8+
res += mat[i][n - 1 - i];
9+
}
10+
11+
return res - (n % 2 == 1 ? mat[n / 2][n / 2] : 0);
12+
}
13+
}

0 commit comments

Comments
 (0)