Leetcode 1677 Solution
This article provides solution to leetcode question 1677 (matrix-diagonal-sum)
Access this page by simply typing in "lcs 1677" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/matrix-diagonal-sum
Solution
class Solution:
def diagonalSum(self, mat: List[List[int]]) -> int:
n = len(mat)
ans = 0
for i in range(n):
ans += mat[i][i] + mat[i][n - 1 - i]
if n % 2 == 1:
ans -= mat[n // 2][n // 2]
return ans