8000 fix buf · leetcoders/LeetCode@93e7d61 · GitHub
[go: up one dir, main page]

Skip to content

Commit 93e7d61

Browse files
author
applewjg
committed
fix buf
Change-Id: I6bfd1675a727f04baaef0b1b3abc602b21cbd179
1 parent c859933 commit 93e7d61

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

DungeonGame.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ for any value of dungeon[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+
5051
class Solution {
5152
public:
5253
int calculateMinimumHP(vector<vector<int> > &dungeon) {
@@ -56,20 +57,20 @@ class Solution {
5657
vector<vector<int>> dp(M, vector<int>(N,0));
5758
dp[M-1][N-1] = 1 - min(0, dungeon[M-1][N-1]);
5859
for (int i = M - 2; i >= 0; --i) {
59-
if (dp[i+1][N-1] - dungeon[i][N-1] < 0) dp[i][N-1] = 1;
60+
if (dp[i+1][N-1] - dungeon[i][N-1] <= 0) dp[i][N-1] = 1;
6061
else dp[i][N-1] = dp[i+1][N-1] - dungeon[i][N-1];
6162
}
6263
for (int j = N - 2; j >= 0; --j) {
63-
if (dp[M-1][j+1] - dungeon[M-1][j] < 0) dp[M-1][j] = 1;
64+
if (dp[M-1][j+1] - dungeon[M-1][j] <= 0) dp[M-1][j] = 1;
6465
else dp[M-1][j] = dp[M-1][j+1] - dungeon[M-1][j];
6566
}
6667
for (int i = M - 2; i >= 0; --i) {
6768
for (int j = N - 2; j >= 0; --j) {
6869
int val = min(dp[i+1][j], dp[i][j+1]);
69-
if (dungeon[i][j] > val) dp[i][j] = 1;
70+
if (dungeon[i][j] >= val) dp[i][j] = 1;
7071
else dp[i][j] = val - dungeon[i][j];
7172
}
7273
}
7374
return max(1,dp[0][0]);
7475
}
75-
};
76+
};

0 commit comments

Comments
 (0)
0