공부/파이썬

#12. 백준 2164번 (python)

김지똥 2025. 2. 6. 16:13

https://www.acmicpc.net/problem/2164

 

 

 

요즘 알고리즘 공부를 하고 있다!!

 

뭐라고 해야지..\

 

 

이건 정답비율 50퍼길래 도전했다

 

from collections import deque

N = int(input())
L = deque(range(1, N+1))


while (len(L)>1):
    L.popleft(0)
    num = L.popleft(0)
    L.append(num)

print(L[0])

 

큐 관련 글 읽으면서 요렇게 작성했는데...

 

뭐가 문제인지 런타임 에러가 난다..

 

결국 정답을 보게되는데

from collections import deque

N = int(input())
deque = deque([i for i in range(1, N+1)])

while(len(deque) >1):
    deque.popleft()
    move_num = deque.popleft()
    deque.append(move_num)
    
print(deque[0])

 

뭐가 다른 건지...

 

다른 건 변수명이랑 

 

요 부분인데....

 

 

뭐가 문제인지 몰라 계속된 시도...

 

요 부분이 틀렸었다. 하하

 

popleft() 자체가 첫 번째 것을 제고하는 건데.. ㅋㅋ

 

암튼 수정했더니 맞았다..

 

아직 시간복잡도 개념이 익숙치 않으니 그에 대한 공부도 해야겠다