Skip to content

Commit f76e41c

Browse files
committed
add 0174 Solution for Java
1 parent b4032dc commit f76e41c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int calculateMinimumHP(int[][] dungeon) {
3+
int row = dungeon.length, column = dungeon[0].length;
4+
int[][] dp = new int[row + 1][column + 1];
5+
for (int i = 0;i <= row;i++) {
6+
Arrays.fill(dp[i], Integer.MAX_VALUE);
7+
}
8+
dp[row][column - 1] = dp[row - 1][column] = 1;
9+
for (int i = row - 1;i > -1;i--) {
10+
for (int j = column - 1;j > -1;j--) {
11+
int min = Math.min(dp[i][j + 1], dp[i + 1][j]);
12+
dp[i][j] = Math.max(min - dungeon[i][j], 1);
13+
}
14+
}
15+
return dp[0][0];
16+
}
17+
}

0 commit comments

Comments
 (0)