We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 29e0600 commit b46cb20Copy full SHA for b46cb20
1 file changed
c++/leetcode/matdiagonalsum.cpp
@@ -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