Skip to content

Commit a7f901c

Browse files
committed
Runtime: 41 ms (Top 5.11%) | Memory: 11.3 MB (Top 10.91%)
1 parent a368ada commit a7f901c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
// Runtime: 41 ms (Top 5.11%) | Memory: 11.3 MB (Top 10.91%)
12
class Solution {
23
public:
34
int diagonalSum(vector<vector<int>>& mat) {
45
int n = mat.size() ;
56
int ans = 0 ;
6-
7+
78
for(int i = 0 ; i < n ; i++){
8-
ans = ans + mat[i][i] + mat[i][n - i - 1] ;
9+
ans = ans + mat[i][i] + mat[i][n - i - 1] ;
910
}
1011
ans = (n & 1) ? ans - mat[n/2][n/2] : ans ;//if n is odd then we have to subtract mat[n/2][n/2] from the ans because we add it twice earlier.
11-
return ans ;
12+
return ans ;
1213
}
13-
};
14+
};

0 commit comments

Comments
 (0)