Java | Simple math | Beats 100% | 6 lines
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n  public int diagonalSum(int[][] mat) {\n    int sum = 0, n = mat.length;\n\n    for (var i=0; i<n; i++)\n      sum += mat[i][i] + mat[i][n-1-i];\n\n    if (n % 2 == 1)\n      sum -= mat[n/2][n/2];\n\n    return sum;\n  }\n}\n```\nIf you like my solution, please upvote it!
['Math', 'Matrix', 'Java']