코딩테스트/백준 (python)
백준 / 2164번 / 카드2 / python 파이썬
seulll
2024. 10. 31. 19:24
문제 : https://www.acmicpc.net/problem/2164
나의 풀이
from collections import deque
q = deque()
n = int(input())
for i in range(1, n+1):
q.append(i)
while len(q) > 1:
q.popleft()
qp = q.popleft()
q.append(qp)
print(q.pop())
큐를 이용하여 쉽게 풀 수 있는 문제이다.
q = deque([i for i in range(1,n+1)])
위와 같이 선언과 함께 큐에 값을 넣을 수도 있다.