Skip to content

Commit 5e6e530

Browse files
author
MaheshReddy-05
committed
08/05/2023
1 parent 852d9d7 commit 5e6e530

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Author: Mahesh Reddy B N
2+
// Problem Link: https://leetcode.com/problems/matrix-diagonal-sum/description/
3+
4+
class Solution {
5+
public int diagonalSum(int[][] mat) {
6+
int ans = 0;
7+
int j =0;
8+
int k = mat.length-1;
9+
for(int i=0;i<mat.length;i++){
10+
ans+= mat[i][j];
11+
ans+=mat[k][i];
12+
if(i==k){
13+
ans-=mat[k][i];
14+
}
15+
k--;
16+
j++;
17+
}
18+
return ans;
19+
}
20+
}

0 commit comments

Comments
 (0)