-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path64(A).cpp
33 lines (28 loc) · 792 Bytes
/
64(A).cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution {
public:
int minPathSum(vector<vector<int>>& A) {
int m=A.size();
int n=A[0].size();
int dp[m][n];
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
dp[i][j]=0;
}
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
dp[i][j]+=A[i][j];
if(i>0 && j>0){
dp[i][j]+=min(dp[i-1][j],dp[i][j-1]);
}
else if(i>0) {
dp[i][j]+=dp[i-1][j];
}
else if(j>0){
dp[i][j]+=dp[i][j-1];
}
}
}
return dp[m-1][n-1];
}
};