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 febb57f commit db04cefCopy full SHA for db04cef
174-dungeon-game.js
@@ -0,0 +1,19 @@
1
+/**
2
+ * @param {number[][]} dungeon
3
+ * @return {number}
4
+ */
5
+const calculateMinimumHP = function(dungeon) {
6
+ if(dungeon.length === 0) return 1
7
+ const rows = dungeon.length
8
+ const cols = dungeon[0].length
9
+
10
+ for(let i = rows - 1 ; i >= 0; i--) {
11
+ for(let j = cols - 1; j >= 0; j--) {
12
+ if(i==rows-1 && j==cols-1) dungeon[i][j]=Math.max(1, 1-dungeon[i][j]);
13
+ else if(i==rows-1) dungeon[i][j]=Math.max(1, dungeon[i][j+1]-dungeon[i][j]);
14
+ else if(j==cols-1) dungeon[i][j]=Math.max(1, dungeon[i+1][j]-dungeon[i][j]);
15
+ else dungeon[i][j]=Math.max(1, Math.min(dungeon[i+1][j], dungeon[i][j+1])-dungeon[i][j]);
16
+ }
17
18
+ return dungeon[0][0]
19
+};
0 commit comments