⚡Easy Solution ✅ || Python3🔥 || 10 Lines Code 🔥|| Matrix || Lets discuss !!⚡
Approach \u2764\uFE0F\nThis Python solution calculates the sum of both the primary and secondary diagonals of a given square matrix.\n\n# Matrix\n---\n\n\n\nA s
# Approach \u2764\uFE0F\nThis Python solution calculates the sum of both the primary and secondary diagonals of a given square matrix.\n\n# Matrix\n---\n\n![image.png](https://assets.leetcode.com/users/images/910ceaf7-61ce-4fd9-8a0d-39c1f27215a2_1712575474.8991244.png)\n\n**A $$square matrix$$ is a type of matrix where the number of rows is equal to the number of columns. In other words, it has the same number of rows and columns.\nFor example:\nA 2x2 matrix (2 rows, 2 columns) is a square matrix.\nA 3x3 matrix (3 rows, 3 columns) is a square matrix.\nA 4x4 matrix (4 rows, 4 columns) is a square matrix.\nAnd so on..**\n\n---\n\n\n1. **Initialization**: \n```\n   - The function takes a square matrix `mat` as input.\n   \n   - It calculates the size of the matrix `n` (given it\'s a square matrix).\n```\n\n2. **Initialize Variables**:\n```\n   - `diagSum`: A list to store the sums of the primary and secondary diagonals.\n   \n   - `odd`: A flag to indicate whether the matrix size is odd or even.\n\n\n```\n3. **Calculate Diagonals**:\n  ```\n   - Iterate over the rows of the matrix (`i = 0`).\n\n   - Iterate over the columns of the matrix (`j` ranging from `0` to `n-1`).\n   \n   - If the matrix size is odd and the current column is the middle column (`j == n//2`),add the element to the primary diagonal sum.\n\n   - Otherwise, add the element to both the primary and secondary diagonal sums.\n   \n```\n\n4. **Return Sum**:\n  ```\n - Return the sum of both diagonal sums (`diagSum[0] + diagSum[1]`).\n\n```\nOverall, this solution efficiently calculates the sums of both the primary and secondary diagonals of the input matrix.\n\n---\n\n\n# Code \u2764\uFE0F\n```\nclass Solution:\n    def diagonalSum(self, mat: List[List[int]]) -> int:\n        n = len(mat[0])\n        diagSum = [0,0]\n        odd = n%2\n        \n        for i in range(1):\n            for j in range(n):\n                if odd and j == (n//2):\n                    diagSum[0] += mat[j][j]\n                else:\n                    diagSum[0] += mat[j][j]\n                    diagSum[1] += mat[j][n-1-j]\n\n        return diagSum[0] + diagSum[1]\n```\n\n# Your upvote is the fuel, my solution needs to soar to new heights! \u2764\uFE0F
['Array', 'Matrix', 'Python3']