```
public int minPathSum(int[][] grid) {
return method1(grid);
}
int method1(int[][]grid){
int dp[]=new int[grid[0].length];
for(int i=0;i<grid.length;i++)
for(int j=0;j<grid[0].length;j++){
int up=(i==0?Integer.MAX_VALUE:dp[j]);
int left=(j==0?Integer.MAX_VALUE:dp[j-1]);
int min=Math.min(up,left);
dp[j]=grid[i][j]+(min==Integer.MAX_VALUE?0:min);
}
return dp[dp.length-1];
}
```

The algorithm above is wrong, since it can not pass the following test case

[

1,Integer.MAX_VALUE-1;

Integer.MAX_VALUE-1,-2

]

however, the algorithm is accepted.