【leetcode_easy_array】1572. Matrix Diagonal Sum

problem

1572. Matrix Diagonal Sum

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;

2. leetcode_discussion;

posted on 2020-10-19 22:06  鹅要长大  阅读(157)  评论(0编辑  收藏  举报

导航