[백준] 카드2 2164번

나의 풀이

from collections import deque
N = int(input())
cards = deque([i for i in range(1, N + 1)])
while len(cards) != 1:
    cards.popleft()
    cards.append(cards.popleft())
print(cards[0])
  • 큐를 만들어서 큐의 사이즈가 1이 될 때까지 제일 첫번째 카드를 제거하고, 그 다음 카드를 맨 뒤로 옮기는 작업을 반복한다.

0개의 댓글