We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b4032dc commit f76e41cCopy full SHA for f76e41c
solution/0100-0199/0174.Dungeon Game/Solution.java
@@ -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