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 c697bee commit 1a27d71Copy full SHA for 1a27d71
174-dungeon-game.js
@@ -17,3 +17,24 @@ const calculateMinimumHP = function(dungeon) {
17
}
18
return dungeon[0][0]
19
};
20
+
21
+// another
22
23
+/**
24
+ * @param {number[][]} dungeon
25
+ * @return {number}
26
+ */
27
+const calculateMinimumHP = function (dungeon) {
28
+ const n = dungeon.length,
29
+ m = dungeon[0].length
30
+ const dp = Array(n + 1).fill(Number.MAX_VALUE)
31
+ dp[n - 1] = 1
32
+ for (let j = m - 1; j >= 0; j--) {
33
+ for (let i = n - 1; i >= 0; i--) {
34
+ dp[i] = Math.min(dp[i], dp[i + 1]) - dungeon[i][j]
35
+ dp[i] = Math.max(1, dp[i])
36
+ }
37
38
+ return dp[0]
39
+}
40
0 commit comments