class Solution:
def diagonalSum(self, mat: List[List[int]]) -> int:
n = len(mat)
answer = 0
for i in range(n):
answer += mat[i][i] + mat[i][n - i - 1]
if n % 2 != 0:
answer -= mat[n // 2][n // 2]
return answer
'CS > 알고리즘' 카테고리의 다른 글
[Leetcode] 34. Find First and Last Position of Element in Sorted Array (0) | 2023.05.09 |
---|---|
[Leetcode] 1498. Number of Subsequences That Satisfy the Given Sum Condition (1) | 2023.05.06 |
[Leetcode] 1456. Maximum Number of Vowels in a Substring of Given Length (0) | 2023.05.06 |
[Leetcode] 649. Dota2 Senate (0) | 2023.05.05 |
[Leetcode] 986. Interval List Intersections (0) | 2023.05.05 |