[프로그래머스] 파이썬 문제풀이 - 숫자 변환하기
첫 풀이 1. DFS와 BFS로 풀었더니 시간초과가 났다 너무 쉽게 풀긴했다 2. 가지치기가 필요한데 더이상 해줄게 없다 def solution(x, y, n): def DFS(x,l): global cnt if x==y and cnt>l: cnt=l if x>y: return DFS(x+n,l+1) DFS(x*2,l+1) DFS(x*3,l+1) if x%2==0 and y%2==1 and n%2==0: return -1 global cnt cnt=9999 DFS(x,0) if cnt==9999: return -1 else: return cnt from collections import deque def solution(x, y, n): answer = 0 q=deque() q.append((x,0)) ..
2023. 5. 4.