Created
March 16, 2021 04:02
-
-
Save SudhanshuGulhane/0354eeda66a8d80fa96cb101f98f2fd1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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