Skip to content

Commit a1eaf19

Browse files
committed
1
1 parent 6204cb7 commit a1eaf19

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class Solution {
2+
public:
3+
int minPathSum(vector<vector<int>>& A) {
4+
5+
int m=A.size();
6+
int n=A[0].size();
7+
8+
int dp[m][n];
9+
10+
for(int i=0;i<m;i++){
11+
for(int j=0;j<n;j++){
12+
dp[i][j]=0;
13+
}
14+
}
15+
for(int i=0;i<m;i++){
16+
for(int j=0;j<n;j++){
17+
18+
dp[i][j]+=A[i][j];
19+
20+
if(i>0 && j>0){
21+
dp[i][j]+=min(dp[i-1][j],dp[i][j-1]);
22+
}
23+
else if(i>0) {
24+
dp[i][j]+=dp[i-1][j];
25+
}
26+
else if(j>0){
27+
dp[i][j]+=dp[i][j-1];
28+
}
29+
}
30+
}
31+
return dp[m-1][n-1];
32+
}
33+
};

0 commit comments

Comments
 (0)