Skip to content

Commit 471c7dd

Browse files
authored
Merge pull request neetcode-gh#1323 from aryanbk/patch-1
Create 120-Triangle.java
2 parents 49d874a + ed72f0f commit 471c7dd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

java/120-Triangle.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int minimumTotal(List<List<Integer>> triangle) {
3+
int l = triangle.size();
4+
int[] dp = new int[l + 1];
5+
6+
for (int row = l - 1; row > -1; --row) {
7+
for (int col = 0; col < row + 1; ++col) {
8+
dp[col] = triangle.get(row).get(col) + Math.min(dp[col], dp[col + 1]);
9+
}
10+
}
11+
12+
return dp[0];
13+
}
14+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy