Java O(n)
trick: checking if two diagonals share center point.\n\n    public int diagonalSum(int[][] mat) {\n        int n = mat.length, res = 0;\n        for (int i = 0;
trick: checking if two diagonals share center point.\n```\n    public int diagonalSum(int[][] mat) {\n        int n = mat.length, res = 0;\n        for (int i = 0; i < n; i++) {\n            res += mat[i][i];\n            if (i != n - 1 - i) res += mat[i][n - 1 - i];\n        }\n        return res;\n    }\n```\n\nOr:\n```\n    public int diagonalSum(int[][] mat) {\n        int n = mat.length, res = 0;\n        for (int i = 0; i < n; i++) {\n            res += mat[i][i];\n            res += mat[i][n - 1 - i];\n        }\n        return res - (n % 2 == 1 ? mat[n / 2][n / 2] : 0);\n    }\n```
[]