Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1323 from aryanbk/patch-1
Browse files Browse the repository at this point in the history
Create 120-Triangle.java
  • Loading branch information
Ahmad-A0 authored Nov 2, 2022
2 parents 49d874a + ed72f0f commit 471c7dd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions java/120-Triangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution {
public int minimumTotal(List<List<Integer>> triangle) {
int l = triangle.size();
int[] dp = new int[l + 1];

for (int row = l - 1; row > -1; --row) {
for (int col = 0; col < row + 1; ++col) {
dp[col] = triangle.get(row).get(col) + Math.min(dp[col], dp[col + 1]);
}
}

return dp[0];
}
}

0 comments on commit 471c7dd

Please sign in to comment.