Skip to content

Commit ac37f7f

Browse files
authored
Create 1289-minimum-falling-path-sum-ii.js
1 parent 4903b1d commit ac37f7f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

1289-minimum-falling-path-sum-ii.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @param {number[][]} arr
3+
* @return {number}
4+
*/
5+
const minFallingPathSum = function (arr) {
6+
const n = arr.length
7+
for (let i = 1; i < n; i++) {
8+
const [m1, m2] = [...arr[i - 1]].sort((a, b) => a - b).slice(0, 2)
9+
for (j = 0; j < n; j++) {
10+
arr[i][j] += arr[i - 1][j] !== m1 ? m1 : m2
11+
}
12+
}
13+
return Math.min(...arr[n - 1])
14+
}

0 commit comments

Comments
 (0)