Skip to content

Commit b46cb20

Browse files
authored
Create matdiagonalsum.cpp
1 parent 29e0600 commit b46cb20

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

c++/leetcode/matdiagonalsum.cpp

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

0 commit comments

Comments
 (0)