본문 바로가기
python-algorithm

[백준] 2161

by 무적김두칠 2021. 2. 23.

1
2
3
4
5
6
7
8
9
10
11
12
import collections
tmp=collections.deque()
for i in range(1,int(input())+1):
    tmp.append(i)
ans=[]
while len(tmp)!=1:
    ans.append(tmp[0])
    tmp.popleft()
    tmp.append(tmp[0])
    tmp.popleft()
ans.append(tmp[0])
print(*ans)
cs

크게 어려운 부분은 없구요 자료구조(Data structure)를 
deque로 이용해서 구현했습니다.

반응형

'python-algorithm' 카테고리의 다른 글

[백준] 2530  (0) 2021.02.23
[백준] 2163  (0) 2021.02.23
[백준] 2052  (0) 2021.02.23
[백준] 1718  (0) 2021.02.23
[백준] 1676  (0) 2021.02.23

댓글