1572.cpp (273B)
1 class Solution { 2 public: 3 int diagonalSum(vector<vector<int>> &mat) { 4 int n = mat.size(), sum = 0; 5 for (int i = 0; i < n; i++) 6 sum += mat[i][i] + mat[i][n - i - 1]; 7 8 if (n % 2) sum -= mat[n / 2][n / 2]; 9 return sum; 10 } 11 };