Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit02b4f8c

Browse files
author
applewjg
committed
fix bug
Change-Id: I1ffde2332f945fa2d07898579be39f6c7562e36f
1 parent8708d09 commit02b4f8c

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

‎DungeonGame.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ Then, let us decide what the health should be at least when leaving room (i, j).
4747
4848
Take D[0][0] and we are good to go. Also, like many other "table-filling" problems, the 2D array D can be replaced with a 1D "rolling" array here.
4949
*/
50-
5150
publicclassSolution {
5251
publicintcalculateMinimumHP(int[][]dungeon) {
5352
intM =dungeon.length;
@@ -56,17 +55,17 @@ public int calculateMinimumHP(int[][] dungeon) {
5655
int[][]dp =newint[M][N];
5756
dp[M-1][N-1] =1 -Math.min(0,dungeon[M-1][N-1]);
5857
for (inti =M -2;i >=0; --i) {
59-
if (dp[i+1][N-1] -dungeon[i][N-1] <0)dp[i][N-1] =1;
58+
if (dp[i+1][N-1] -dungeon[i][N-1] <=0)dp[i][N-1] =1;
6059
elsedp[i][N-1] =dp[i+1][N-1] -dungeon[i][N-1];
6160
}
6261
for (intj =N -2;j >=0; --j) {
63-
if (dp[M-1][j+1] -dungeon[M-1][j] <0)dp[M-1][j] =1;
62+
if (dp[M-1][j+1] -dungeon[M-1][j] <=0)dp[M-1][j] =1;
6463
elsedp[M-1][j] =dp[M-1][j+1] -dungeon[M-1][j];
6564
}
6665
for (inti =M -2;i >=0; --i) {
6766
for (intj =N -2;j >=0; --j) {
6867
intval =Math.min(dp[i+1][j],dp[i][j+1]);
69-
if (dungeon[i][j] >val)dp[i][j] =1;
68+
if (dungeon[i][j] >=val)dp[i][j] =1;
7069
elsedp[i][j] =val -dungeon[i][j];
7170
}
7271
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp