Skip to content

Commit 15c0d42

Browse files
authored
add Space Complexity( O(n) ) & simpler solution
1 parent 8649a12 commit 15c0d42

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

solution/0120.Triangle/Solution2.cpp

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

0 commit comments

Comments
 (0)