hint
There will be overlap of elements in the primary and secondary diagonals if and only if the length of the matrix is odd, which is at the center.
Synopsis
Accumulate both diagonal sums simultaneously.
Subtract the middle sum once if it was added twice.
solution#1:
code:
注意,如何求解方阵的对角线元素之和。
solution#2: one Liner Solutions;
code
参考
1. leetcode_easy_array_1572. Matrix Diagonal Sum;
完