Skip to content

Commit 0853edc

Browse files
authored
Merge pull request gzc426#781 from MMzhe/patch-62
Create sourcema.md
2 parents f7e9e72 + 9ee7d1b commit 0853edc

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

2019.01.29-leetcode64/sourcema.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# leetcode 64
2+
class Solution {
3+
public int minPathSum(int[][] grid) {//动态规划模板题,直接手撸
4+
if(grid==null||grid.length==0||grid[0].length==0){
5+
return 0;
6+
}
7+
int[][] dp=new int[grid.length][grid[0].length];
8+
dp[0][0]=grid[0][0];
9+
for(int i=1;i<grid[0].length;i++){
10+
dp[0][i]=dp[0][i-1]+grid[0][i];
11+
}
12+
for(int i=1;i<grid.length;i++){
13+
dp[i][0]=dp[i-1][0]+grid[i][0];
14+
}
15+
for(int i=1;i<grid.length;i++){
16+
for(int j=1;j<grid[0].length;j++){
17+
dp[i][j]=Math.min(dp[i][j-1],dp[i-1][j])+grid[i][j];
18+
}
19+
}
20+
return dp[grid.length-1][grid[0].length-1];
21+
}
22+
}

0 commit comments

Comments
 (0)