본문 바로가기
알고리즘 & 코딩 테스트/[Java]프로그래머스

[프로그래머스_Java] Lv.0 개미 군단

by heosj 2024. 5. 20.
문제

 


풀이

#1

class Solution {
    public int solution(int hp) {
        int answer = 0;
        int[] attacks = {5,3,1};
        
        for(int attack : attacks) {
            answer += hp / attack;
            hp %= attack;
        }
        return answer;
    }
}

 

#2

class Solution {
    public int solution(int hp) {
        int general = hp/5;
        int soldier = hp%5/3;
        int work = hp%5%3;
        return general + soldier + work;
    }
}