[java] 프로그래머스 - 개미 군단

0

[문제링크 - 프로그래머스 - 개미 군단] https://school.programmers.co.kr/learn/courses/30/lessons/120837?language=java

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

class Solution1 {
    public int solution(int hp) {
        int answer = 0;

        answer = (hp/5) + ((hp%5) / 3) + ((hp%5) % 3);

        return answer;
    }
}
profile
초심 잃지 않기

0개의 댓글