Skip to content

Commit 8ee2c5d

Browse files
authored
Update 931-minimum-falling-path-sum.js
1 parent cb08126 commit 8ee2c5d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

931-minimum-falling-path-sum.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/**
2+
* @param {number[][]} A
3+
* @return {number}
4+
*/
5+
const minFallingPathSum = function(A) {
6+
for (let i = 1, rows = A.length; i < rows; i++) {
7+
for (let j = 0, cols = A[0].length; j < cols; j++) {
8+
A[i][j] += Math.min(
9+
getValueOrMax(A, i - 1, j - 1),
10+
getValueOrMax(A, i - 1, j),
11+
getValueOrMax(A, i - 1, j + 1)
12+
);
13+
}
14+
}
15+
return Math.min(...A[A.length - 1]);
16+
};
17+
18+
function getValueOrMax(A, i, j) {
19+
return A[i][j] !== undefined ? A[i][j] : Number.MAX_VALUE;
20+
}
21+
22+
// another
23+
124
/**
225
* @param {number[][]} A
326
* @return {number}

0 commit comments

Comments
 (0)