Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- COS PRO
- dfs
- 문제해결
- priorityqueue
- math
- 시뮬레이션
- oracle
- 이분탐색
- 건강
- BOJ
- 백준
- 운동기록
- 투포인터
- 코딩테스트
- greedy
- BFS
- 문제풀이
- DP
- SQL
- MySQL
- Java
- 자바
- 프로그래머스
- 문자열
- 러닝일지
- 알고리즘
- db
- SWEA
- binary search
- 코테
Archives
- Today
- Total
슈콩
[프로그래머스] Lv.2 마법의 엘리베이터 본문


[문제]
https://school.programmers.co.kr/learn/courses/30/lessons/148653
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
[소스 코드]
class Solution {
public int solution(int storey) {
int answer = 0;
while(storey!=0){
int n = storey % 10;
storey /= 10;
if(n==0) continue;
if(n<5){
answer += n;
}
else if(n>5){
answer += (10 - n);
storey++;
}
else{
answer += 5;
if(storey % 10 >= 5){
storey++;
}
}
}
return answer;
}
}
'Algorithms > Programmers' 카테고리의 다른 글
| [프로그래머스] Lv.2 호텔 대실 (0) | 2025.10.22 |
|---|---|
| [프로그래머스] Lv.2 시소 짝꿍 (0) | 2025.10.22 |
| [프로그래머스] Lv.2 연속된 부분 수열의 합 (0) | 2025.10.18 |
| [프로그래머스] Lv.2 큰 수 만들기 (0) | 2025.10.17 |
| [프로그래머스] Lv.2 다리를 지나는 트럭 (0) | 2025.10.17 |