Skip to content

Commit 3ff1b8f

Browse files
committed
https://leetcode.cn/problems/matrix-diagonal-sum/
1 parent 4fc8190 commit 3ff1b8f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ leetcode 测试
1010

1111
##### 包含的内容如下
1212

13+
https://leetcode.cn/problems/matrix-diagonal-sum/
14+
1315
https://leetcode.cn/problems/thousand-separator/
1416

1517
https://leetcode.cn/problems/count-odd-numbers-in-an-interval-range/

matrix-diagonal-sum/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default function diagonalSum(e: number[][]) {
2+
return e.reduce(
3+
(e, _n, r, t) =>
4+
r === t.length - r - 1
5+
? e + t[r][r]
6+
: e + t[r][r] + t[r][t.length - r - 1],
7+
0
8+
);
9+
}

0 commit comments

Comments
 (0)