Skip to content

Commit

Permalink
Create 8 May | 1572. Matrix Diagonal Sum.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
SumitPareek2401 authored May 8, 2023
1 parent 51bf43f commit 422867d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 8 May | 1572. Matrix Diagonal Sum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public:
int diagonalSum(vector<vector<int>>& mat) {
int s = 0, i = 0, j = 0;
while(i < mat.size()){
s = s+mat[i][j];
i++;
j++;
}
j = mat.size()-1, i = 0;
while(i < mat.size()){
if(i!= j)
s = s+mat[i][j];
i++;
j--;
}
return s;
}
};

0 comments on commit 422867d

Please sign in to comment.