상세 컨텐츠

본문 제목

#12. 백준 2164번 (python)

공부/파이썬

by 김지똥 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() 자체가 첫 번째 것을 제고하는 건데.. ㅋㅋ

 

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

 

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

'공부 > 파이썬' 카테고리의 다른 글

#13. 백준 1158번 (python)  (0) 2025.04.24
#13. 백준 2720번 (python)  (0) 2025.02.25
Optimization Methods in Finance Chapter 1.2  (2) 2024.10.27
[파이썬] return과 print의 차이  (0) 2024.08.26
#11. 백준 11718번 (python)  (0) 2024.08.10

관련글 더보기