64. Minimum Path Sum

Posted warmland

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了64. Minimum Path Sum相关的知识,希望对你有一定的参考价值。

和unique path一样的

 1     public int minPathSum(int[][] grid) {
 2         if(grid == null || grid.length == 0 || grid[0].length == 0) {
 3             return 0;
 4         }
 5         int len = grid[0].length;
 6         int[] res = new int[len];
 7         res[0] = grid[0][0];
 8         for(int i = 1; i < len; i++) {
 9             res[i] = res[i-1]  + grid[0][i];
10         }
11         for(int i = 1; i < grid.length; i++) {
12             for(int j = 0; j < len; j++) {
13                 if(j == 0) {
14                     res[j] += grid[i][j];
15                 } else {
16                     res[j] = Math.min(res[j], res[j-1]) + grid[i][j];
17                 }
18             }
19         }
20         return res[len-1];
21     }

 

以上是关于64. Minimum Path Sum的主要内容,如果未能解决你的问题,请参考以下文章

64. Minimum Path Sum

64. Minimum Path Sum

64. Minimum Path Sum

64.Minimum Path Sum

64. Minimum Path Sum

64. Minimum Path Sum