250x250
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 |
Tags
- 프록시
- html form
- 오버라이딩
- 코딩테스트
- 프로그래머스
- 오블완
- 의존관계
- java
- 인터페이스
- 추상클래스
- 싱글톤
- fielderror
- HttpServletResponse
- 백준
- 스프링
- 참조변수
- 스프링컨테이너
- 티스토리챌린지
- @configuration
- equals()
- objecterror
- 예외와 트랜잭션 커밋
- 서블릿
- 다익스트라
- http 메시지 컨버터
- 코드트리조별과제
- 테스트코드
- 코드트리
- DI
- 김영한
Archives
- Today
- Total
minOS
프로그래머스 점프와 순간 이동 본문
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/12980
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
처음에 BFS 풀었다가 효율성에서 막혔다
from collections import deque
def solution(n):
q= deque()
visited = [0 for _ in range(n+1)]
q.append((1,1))
visited[1] =1
while q :
x,step = q.popleft()
if x == n :
return step
for i in [2*x , x +1] :
if 0<= i <= n and visited[i]:
continue
elif 0<= i <= n and not visited[i] and i == 2*x:
q.append((2*x,step))
visited[2*x] =1
elif 0<= i <= n and not visited[i] and i == x+1:
q.append((x+1,step+1))
visited[x+1] =1
정확도, 효율성 모두 통과한 코드
def solution(n):
ans =0
while n != 0:
if n % 2 ==0:
n/=2
else:
n-=1
ans+=1
return ans728x90
'Problem Solving > 프로그래머스' 카테고리의 다른 글
| 프로그래머스 단속카메라 (1) | 2025.07.25 |
|---|---|
| 프로그래머스 카펫 (3) | 2025.07.24 |
| 프로그래머스 거리두기 확인하기 (1) | 2025.07.11 |
| 프로그래머스 야근 지수 (0) | 2025.07.07 |
| 프로그래머스 가장 많이 받은 선물 (0) | 2025.07.05 |