There was an error while loading. Please reload this page.
1 parent 160c00f commit 513d082Copy full SHA for 513d082
src/main/java/codechallenges/dynamicprogramming/StrategyGameOne.java
@@ -20,7 +20,30 @@
20
public class StrategyGameOne {
21
22
public int solve(int[] hitPoints) {
23
- return 0;
+
24
+ int sum = 0;
25
+ for (int hp : hitPoints ) {
26
+ sum += hp;
27
+ }
28
29
+ int[] hits = new int[sum + 1];
30
+ hits[0] = 0;
31
32
+ for (int i = 1; i <= sum; i++) {
33
34
+ hits[i] = hits[i - 1] + 1;
35
36
+ if (i - 9 >= 0 && hits[i - 9] < hits[i]) {
37
+ hits[i] = hits[i - 9] + 1;
38
39
40
+ if (i - 3 >= 0 && hits[i - 3] < hits[i]) {
41
+ hits[i] = hits[i - 3] + 1;
42
43
44
45
46
+ return hits[sum];
47
}
48
49
int hitPoints(int current) {
0 commit comments