Simple Java approach O(N).
Intuition\n Describe your first thoughts on how to solve this problem. \nIn the problem we are supposed to calculate the diagonal sum (Both Primary and Secondar
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIn the problem we are supposed to calculate the diagonal sum (Both Primary and Secondary), So we can see the pattern that in case of the number of matrices is oddly one of the elements will appear in both of the diagonal and it is needed to be ignored.  \n# Approach\n<!-- Describe your approach to solving the problem. -->\nSo we will follow the basic approach of creating 2 for loops 1 for the primary diagonal and another for the secondary diagonal and save the sum in the sum variable. If the matrix (n*n) is having an odd number of rows we will subtract the middle element ie. Matrix [n/mat. length] [n/mat. length]\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->O(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --> O(1)\n\n# Code\n```\nclass Solution {\n    public int diagonalSum(int[][] mat) {\n        int sum =0;\n        for (int i = 0; i < mat.length; i++) {\n            sum += mat[i][i];\n        }\n        // for Sec Diagonal\n        for (int i = 0; i < mat.length; i++) {\n            \n            sum += mat[i][mat.length - i - 1];\n        }\n        if (mat.length % 2 != 0 && mat.length/2 == mat.length - mat.length/2 - 1) {\n            sum -= mat[mat.length/2][mat.length/2];\n        }\n        return sum;\n    }\n}\n```
['Java']