PS

11866 파이썬

dlxortmd123 2022. 7. 28. 17:28
import collections

n, k = map(int, input().split())
q = collections.deque()
for i in range(1,n+1):
    q.appendleft(i)
print('<', end='')
while len(q) > 1:
    q.rotate(k)
    a = q.popleft()
    print(a, end=", ")
print(q.pop(), end='')
print('>')
  • list 대신 queue 이용
    • queue의 rotate 메소드를 사용하여 삭제하려는 값을 가장 왼 쪽에 위치시킴