[PYTHON] Best solution with explanation. SC : O(1) TC : O(n)
\nclass Solution:\n    def diagonalSum(self, mat: List[List[int]]) -> int:\n        """\n        The primary diagonal is formed by the elements A00, A11, A22, A
```\nclass Solution:\n    def diagonalSum(self, mat: List[List[int]]) -> int:\n        """\n        The primary diagonal is formed by the elements A00, A11, A22, A33.\n        Condition for Primary Diagonal:\n            The row-column condition is row = column.\n\n        The secondary diagonal is formed by the elements A03, A12, A21, A30. \n        Condition for Secondary Diagonal:\n            The row-column condition is row = numberOfRows - column -1.\n        """\n        s = 0\n        l , mid = len(mat), len(mat)//2\n        for i in range(l):\n            s += mat[i][i] # primary diagonal\n            s += mat[len(mat)-i-1][i] # secondary diagonal\n        \n        # If the mat is odd, then diagonal will coincide, so subtract the middle element\n        if l%2 != 0:\n            s -= mat[mid][mid]\n        \n        return s\n        \n\n\n\n```
['Python', 'Java', 'Python3']