We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7b9b9d6 commit 4532228Copy full SHA for 4532228
0931-minimum-falling-path-sum/0931-minimum-falling-path-sum.cpp
@@ -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