We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4cd32ea commit 580b384Copy full SHA for 580b384
64. Minimum Path Sum
@@ -0,0 +1,23 @@
1
+public class Solution {
2
+ public int minPathSum(int[][] grid) {
3
+ if(grid == null || grid.length == 0 || grid[0].length == 0){
4
+ return Integer.MAX_VALUE;
5
+ }
6
+ int row = grid.length;
7
+ int col = grid[0].length;
8
+ for (int i = 0; i < row; i++) {
9
+ for (int j = 0; j < col; j++) {
10
+ if (i == 0 && j != 0) {
11
+ grid[i][j] = grid[i][j] + grid[i][j - 1];
12
+ } else if (i != 0 && j == 0) {
13
+ grid[i][j] = grid[i][j] + grid[i - 1][j];
14
+ } else if (i == 0 && j == 0) {
15
+ grid[i][j] = grid[i][j];
16
+ } else {
17
+ grid[i][j] = Math.min(grid[i][j - 1], grid[i - 1][j]) + grid[i][j];
18
19
20
21
+ return grid[row - 1][col - 1];
22
23
+}
0 commit comments