🚨시간초과가 나버려욧!
import sys
input = sys.stdin.readline
N = int(input())
arr = list(i for i in range(N,0,-1))
while len(arr) > 1:
arr.pop()
arr.insert(0, arr.pop())
print(arr[0])
👌중간에 삽입 및 삭제가 많으므로 Dequeue 를 사용해야합니다.
import sys
input = sys.stdin.readline
from collections import deque # 완전 기초 모듈
N = int(input().strip())
queue = deque(range(N,0,-1))
while len(queue) > 1:
queue.pop()
queue.appendleft(queue.pop())
print(queue[0])
'Baekjoon' 카테고리의 다른 글
28279. 덱 2 (1) | 2025.02.19 |
---|---|
11866. 요세푸스 문제 0 (1) | 2025.02.19 |
18258. 큐 2 (0) | 2025.02.19 |
1157. 단어 공부 (0) | 2025.02.19 |
21862. 사각형 그리기 게임 (4) | 2025.02.17 |