Skip to content

Commit

Permalink
Q1572 added.
Browse files Browse the repository at this point in the history
  • Loading branch information
isinsuarici committed Mar 14, 2023
1 parent 11a9f15 commit 43db3eb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions E_1572_MatrixDiagonalSum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution {
public int diagonalSum(int[][] mat) {
int ret = 0;
for (int i=0; i<mat.length; i++) {
ret += mat[i][i];
ret += mat[mat.length-1-i][i];
}
return (mat.length%2==0) ? ret : ret-mat[mat.length/2][mat.length/2];
}
}

0 comments on commit 43db3eb

Please sign in to comment.