public static int minPathSum(int[][] grid){
  if (grid == null || grid.length == 0)   return 0;
  int m=grid.length;
  int n=grid[0].length;
  int[] rowSum=new int[n];
  rowSum[0]=grid[0][0];
  for (int col=1; col < n; col++)   rowSum[col]=rowSum[col - 1] + grid[0][col];
  for (int row=1; row < m; row++) {
    rowSum[0]+=grid[row][0];
    for (int col=1; col < n; col++) {
      rowSum[col]=Math.min(rowSum[col - 1],rowSum[col]) + grid[row][col];
    }
  }
  return rowSum[n - 1];
}

public static int minPathSum ( int [ ] [ ] grid ) { if ( grid == null || grid . length == 0 ) return 0 ; int m = grid . length ; int n = grid [ 0 ] . length ; int [ ] rowSum = new int [ n ] ; rowSum [ 0 ] = grid [ 0 ] [ 0 ] ; for ( int col = 1 ; col < n ; col ++ ) rowSum [ col ] = rowSum [ col - 1 ] + grid [ 0 ] [ col ] ; for ( int row = 1 ; row < m ; row ++ ) { rowSum [ 0 ] += grid [ row ] [ 0 ] ; for ( int col = 1 ; col < n ; col ++ ) { rowSum [ col ] = Math . min ( rowSum [ col - 1 ] , rowSum [ col ] ) + grid [ row ] [ col ] ; } } return rowSum [ n - 1 ] ; }
dp . bottom - up row by row , use an array to store values
