matrix diagonal sum

🏠

Variation from r0bertz

1 class Solution:
2     def diagonalSum(self, A: List[List[int]]) -> int:
3         n = len(A)
4         return sum(A[i][i] + A[i][~i] for i in range(n)) - (0, A[n // 2][n // 2])[n % 2]