Skip to content

Commit 5f4d920

Browse files
BarklimBarklim
authored andcommitted
Create 1572.js
1 parent 3237c5e commit 5f4d920

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var diagonalSum = function(mat) {
6+
7+
};
8+
9+
const example1 = diagonalSum([[1,2,3],[4,5,6],[7,8,9]]); // 25
10+
const example2 = diagonalSum([[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]]); // 8
11+
12+
console.log(example1);
13+
console.log(example2);
14+
15+
// var diagonalSum = function(mat) {
16+
// let n = mat.length;
17+
// let row = 0;
18+
19+
// const lambda = (sum, vec) => {
20+
// sum += vec[row];
21+
// if (row !== n - row - 1) sum += vec[n - row - 1];
22+
// row++;
23+
// return sum;
24+
// };
25+
26+
// return mat.reduce(lambda, 0);
27+
// };

example/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,5 @@ Better order to solve problems
257257
### [0.Basic](https://github.com/Barklim/leetcode-javascript/tree/master/example/ProgrammingSkills/1.Simulation)
258258

259259
58. Length of Last Word
260-
1041. Robot Bounded In Circle
260+
1041. Robot Bounded In Circle
261+
1572. Matrix Diagonal Sum

0 commit comments

Comments
 (0)