链接: https://oj.leetcode.com/problems/minimum-path-sum/
简单的动态规划.
[i][j]表示到达位置(i,j)时的最小sum
public class Solution { public int minPathSum(int[][] grid) { int n=grid.length; int m=grid[0].length; for(int i=0;i<n;i++) for(int j=0;j<m;j++) { if(i==0&&j>0) grid[i][j]+=grid[i][j-1]; if(i>0&&j==0) grid[i][j]+=grid[i-1][j]; if(i>0&&j>0) grid[i][j]+=Math.min(grid[i-1][j],grid[i][j-1]); } return grid[n-1][m-1]; } }
天下武功,唯快不破