📌📌A very easy to understand sol. using Python. More than 96% beats
Approach\n Describe your approach to solving the problem. \n\nFirst lets find a way to get all the diagonal elements.\n\nThe principel diagonal element can be f
# Approach\n<!-- Describe your approach to solving the problem. -->\n\nFirst lets find a way to get all the diagonal elements.\n\nThe principel diagonal element can be found at `(0,0),(1,1),(2,2),...,(i,i)` places.\n\n<img src="https://assets.leetcode.com/users/images/6b3e8a54-3237-4d4f-8c17-f21c610285c6_1676388100.3670912.png" width="200" height="200" />\n\nTo get all the elements of this diagonal we use a for loop. Then sum up all the elements.\n<hr>\n\nNow, for the counter diagonal elements, \n\n\n<img src = "https://assets.leetcode.com/users/images/999aeb61-1a7c-4baf-81e5-abd48a644144_1676388368.529526.png"\nwidth = "200"/>\n\nuse this `[row][col] = [i][n-i-1]`\nand add all the elements.\n<hr>\n\nAfter that we have to subtract the center diagonal element, which we added twice: first from the principal diagonal, second from the counter diagonal(only in odd length matrix).\n\nTo remove that element, first we have to check wheather our sq. matrix is of odd length or even length.\n\nIf `len(matrix)` is odd then simply remove the center element i.e. \nfor a \n    `3x3` matrix : `[1,1]`\n    `5x5` matrix :` [2,2]`\n    `7x7` matrix : `[3,3]`\n    `...`\n    `nxn` matrix :` [n//2,n//2]`\n\nAnd if `len(matrix)` is even, then no need to do anything\n\n\n# Code\n```\nclass Solution:\n    def diagonalSum(self, mat: List[List[int]]) -> int:\n        n = len(mat)\n        sum =0\n        for i in range(n):\n            sum += mat[i][i] #sum of principal diagonal\n            sum += mat[i][n-i-1]  #sum of counter diagonal\n        \n        if n%2==1:\n            sum -= mat[n//2][n//2]\n        return sum\n```\n\n<img src=\'https://assets.leetcode.com/users/images/26e0d290-2307-44c7-9aac-3bb5fb65ad4d_1684683655.5701103.png\'/>
['Python', 'Python3']