Skip to content

Commit 4532228

Browse files
committed
Time: 11 ms (80.62%), Space: 13.2 MB (5.08%) - LeetHub
1 parent 7b9b9d6 commit 4532228

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
int minFallingPathSum(vector<vector<int>>& A) {
4+
int m = A.size();
5+
vector<vector<int>> t(m, vector<int>(m));
6+
7+
for(int col = 0; col<m; col++) {
8+
t[0][col] = A[0][col];
9+
}
10+
11+
for(int row = 1; row < m; row++) {
12+
for(int col = 0; col < m; col++) {
13+
t[row][col] = A[row][col] + min({t[row-1][col],
14+
t[row-1][max(0, col-1)],
15+
t[row-1][min(m-1, col+1)]});
16+
}
17+
}
18+
19+
return *min_element(t[m-1].begin(), t[m-1].end());
20+
}
21+
};

0 commit comments

Comments
 (0)