
내가 작성한 코드
class Solution {
public int solution(int hp) {
int answer = 0; // 개미 마리 수를 담을 변수
// hp가 5보다 크거나 같으면
if (hp >= 5) {
// 5로 나누고 몫은 answer에 담고 나머지는 hp에 담는다
answer += hp / 5;
hp = hp % 5;
}
// 위와 같지만 조건이 다름
if (hp >= 3) {
answer += hp / 3;
hp = hp % 3;
}
if (hp >= 1) {
answer += hp;
hp = 0;
}
return answer;
}
}
다른 사람의 코드
class Solution {
public int solution(int hp) {
return hp / 5 + (hp % 5 / 3) + hp % 5 % 3;
}
}
Share article