Skip to content

Commit 8ae5c73

Browse files
authored
Create 120. Triangle (#896)
2 parents 6b7436a + e27f93a commit 8ae5c73

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

120. Triangle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
int minimumTotal(vector<vector<int>>& triangle) {
4+
int n = triangle.size();
5+
vector<vector<int>> dp(triangle.begin(), triangle.end());
6+
for (int i = n-2; i >= 0; i--) {
7+
for (int k = 0; k <= i; k++) {
8+
dp[i][k] += min(dp[i+1][k], dp[i+1][k+1]);
9+
}
10+
}
11+
return dp[0][0];
12+
}
13+
};

0 commit comments

Comments
 (0)