```
public class Solution {
private int min = Integer.MAX_VALUE;
public int minPathSum(int[][] grid) {
dfs(grid, 0,0,grid[0][0]);
return min;
}
private void dfs(int[][] grid, int row, int col, int sum){
if(row>=grid.length-1 && col>=grid[row].length-1){
min = Math.min(sum, min);
return;
}else if(row==grid.length-1){
dfs(grid, row, col+1, sum+grid[row][col+1]);
}else if(col==grid[row].length-1){
dfs(grid, row+1, col, sum+grid[row+1][col]);
}else{
dfs(grid, row+1, col, sum+grid[row+1][col]);
dfs(grid, row, col+1, sum+grid[row][col+1]);
}
}
}
```