- 난이도: Lv2
프로그래머스 링크: https://school.programmers.co.kr/learn/courses/30/lessons/148653
풀이 링크(GitHub): hayannn/CodingTest_Java/프로그래머스/2/마법의 엘리베이터
풀이 시간 : 24분
class Solution {
public int solution(int storey) {
int answer = 0;
while (storey > 0) {
int digit = storey % 10;
int next = (storey / 10) % 10;
boolean roundUp = (digit > 5) || (digit == 5 && next >= 5);
answer += roundUp ? 10 - digit : digit;
if (roundUp) {
storey += 10 - digit;
}
storey /= 10;
}
return answer;
}
}