Skip to content

Commit a9b1ceb

Browse files
authored
Create 0120-triangle.kt
1 parent 5c6d7be commit a9b1ceb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

kotlin/0120-triangle.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
fun minimumTotal(triangle: List<List<Int>>): Int {
3+
val dp = IntArray(triangle.last().size + 1)
4+
5+
for (row in triangle.reversed()) {
6+
for ((i,n) in row.withIndex())
7+
dp[i] = minOf(dp[i], dp[i + 1]) + n
8+
}
9+
10+
return dp[0]
11+
}
12+
}

0 commit comments

Comments
 (0)