Using just one loop and an if | Java 100% faster | Easy to understand
\nclass Solution {\n    public int diagonalSum(int[][] mat) {\n        \n        int sum = 0;\n        int n = mat.length;\n        \n        for(int i = 0; i <
```\nclass Solution {\n    public int diagonalSum(int[][] mat) {\n        \n        int sum = 0;\n        int n = mat.length;\n        \n        for(int i = 0; i < n; i++){\n            sum += mat[i][i] + mat[i][n-i -1];\n        }\n        \n        if(n % 2 != 0) sum -= mat[n/2][n/2];\n        \n        return sum;\n    }\n}\n```\n\nImplement it in your notebook to get a better idea of the formula.
['Java']