https://school.programmers.co.kr/learn/courses/30/lessons/120837
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
정답
public class Solution {
public int solution(int hp) {
int answer = 0;
int[] ant = {5, 3, 1};
for (int antType : ant) {
answer += hp / antType; // 현재 개미 종류로 사용 가능한 개미의 수를 더함
hp %= antType;
}
return answer;
}
}
다른 사람의 풀이
class Solution {
public int solution(int hp) {
int answer = hp / 5;
hp %= 5;
answer += hp / 3;
hp %= 3;
answer += hp / 1;
return answer;
}
}
'Java > 프로그래머스' 카테고리의 다른 글
[JAVA] 프로그래머스 - 외계행성의 나이 (0) | 2024.04.22 |
---|---|
[JAVA] 프로그래머스 - 특정 문자 제거하기 (0) | 2024.04.22 |
[JAVA] 프로그래머스 - 순서쌍의 개수 (1) | 2024.04.20 |
[JAVA] 프로그래머스 - 배열 자르기 (0) | 2024.04.20 |
[JAVA] 프로그래머스 - 양꼬치 (0) | 2024.04.20 |