-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdungeonGame.java
More file actions
31 lines (28 loc) · 964 Bytes
/
dungeonGame.java
File metadata and controls
31 lines (28 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class dungeonGame {
public static int calculateMinimumHP(int[][] dungeon) {
int cols = dungeon[0].length;
int rows = dungeon.length;
int minCummul = 0;
System.out.println("cols: " + cols + ", rows: " + rows);
for (int i = 0; i < cols; i++) {
int sum = 0;
for (int j = 0; j < rows; j++) {
sum += dungeon[i][j];
minCummul = Math.min(minCummul, sum);
System.out.println("element: " + dungeon[i][j]);
System.out.println("i: " + i + " ,j: " + j + " ,sum: " + sum + ", minCumm: " + minCummul);
}
}
return 0;
}
public static void main(String[] args) {
int dungeon[][] = {{-2,-3,3},{-5,-10,1},{10,30,-5}};
System.out.println("output: " + calculateMinimumHP(dungeon));
}
}
/*
* track cummulMin
* iterate through subarrays
* cummulMin = Math.min(cummul, cummulMin)
*
*/