解題說明
C++ 解法
複雜度分析
虛擬碼
1. Let n = number of rows in mat 2. Initialize sum = 0 3. For each row i from 0 to n-1: a. sum += mat[i][i] (primary diagonal) b. sum += mat[i][n-1-i] (secondary diagonal) 4. If n is odd: a. sum -= mat[n/2][n/2] (remove double-counted center) 5. Return sum