MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / diagonalSum

Method diagonalSum

Java/matrix-diagonal-sum.java:10–28  ·  view source on GitHub ↗
(int[][] mat)

Source from the content-addressed store, hash-verified

8*/
9class Solution {
10 public int diagonalSum(int[][] mat) {
11
12 int diagonalSum = 0;
13 int len = mat.length - 1;
14
15 for(int i=0; i<mat.length; i++){
16 for(int j=0; j<mat[i].length; j++){
17
18 if(i == j){
19 diagonalSum += mat[i][j];
20 }
21 else if(i == (len-j)){
22 diagonalSum += mat[i][j];
23 }
24 }
25 }
26
27 return diagonalSum;
28 }
29}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected