Skip to content

Instantly share code, notes, and snippets.

@SudhanshuGulhane
Created March 16, 2021 04:02
Show Gist options
  • Save SudhanshuGulhane/0354eeda66a8d80fa96cb101f98f2fd1 to your computer and use it in GitHub Desktop.
Save SudhanshuGulhane/0354eeda66a8d80fa96cb101f98f2fd1 to your computer and use it in GitHub Desktop.
class Solution {
public int calculate(int[][] grid, int i, int j)
{
if (i == grid.length || j == grid[0].length)
{
return Integer.MAX_VALUE;
}
if (i == grid.length - 1 && j == grid[0].length - 1)
{
return grid[i][j];
}
return grid[i][j] +
Math.min(calculate(grid, i + 1, j), calculate(grid, i, j + 1));
}
public int minPathSum(int[][] grid) {
return calculate(grid, 0, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment