반응형
import java.util.*;
class Solution {
public int solution(int[] bandage, int health, int[][] attacks) {
Map<Integer, Integer> attackInfo = new HashMap<>();
int now_hp = health;
int successcount = 0;
for(int[] attack : attacks) {
attackInfo.put(attack[0], attack[1]);
}
for(int i=1; i<=attacks[attacks.length-1][0]; i++){
if(attackInfo.containsKey(i)){
now_hp -= attackInfo.get(i);
successcount = 0;
}
else {
now_hp+=bandage[1];
successcount++;
if(successcount == bandage[0]){
now_hp += bandage[2];
successcount = 0;
}
if(now_hp > health) {
now_hp = health;
}
}
if(now_hp <= 0){
return -1;
}
}
return now_hp;
}
}
'코딩테스트 > 자바 코딩테스트' 카테고리의 다른 글
[Java] 프로그래머스 Lv.1 같은 숫자는 싫어 (0) | 2024.04.16 |
---|---|
[JAVA] 프로그래머스 Lv.1 부족한 금액 계산하기 (0) | 2024.04.15 |
[JAVA] 프로그래머스 PEEC 기출문제 10번 / 데이터 분석 (1) | 2024.04.12 |
[JAVA] 프로그래머스 Lv.1 최소직사각형 (1) | 2024.04.10 |
프로그래머스 Lv.0 배열 만들기2 Java (1) | 2024.02.07 |