Skip to content

Commit 33363aa

Browse files
authored
Update 2.py
1 parent 6c7661b commit 33363aa

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

โ€Ž21/2.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys
2+
import heapq
3+
input = sys.stdin.readline
4+
5+
def heapsort(iterable):
6+
h = []
7+
result = []
8+
# ๋ชจ๋“  ์›์†Œ๋ฅผ ์ฐจ๋ก€๋Œ€๋กœ ํž™์— ์‚ฝ์ž…
9+
for value in iterable:
10+
heapq.heappush(h, value)
11+
# ํž™์— ์‚ฝ์ž…๋œ ๋ชจ๋“  ์›์†Œ๋ฅผ ์ฐจ๋ก€๋Œ€๋กœ ๊บผ๋‚ด์–ด ๋‹ด๊ธฐ
12+
for i in range(len(h)):
13+
result.append(heapq.heappop(h))
14+
return result
15+
16+
n = int(input())
17+
arr = []
18+
19+
for i in range(n):
20+
arr.append(int(input()))
21+
22+
res = heapsort(arr)
23+
24+
for i in range(n):
25+
print(res[i])

0 commit comments

Comments
ย (0)