[백준] 10989번

코린이·2022년 5월 5일
0

백준

목록 보기
20/38

📢 10989번 문제


백준 문제 링크

🔎 풀이

사용언어 : python
카운팅 정렬 사용

카운팅 정렬(Counting Star)이란?

  • 정렬 알고리즘
  • 시간 복잡도 O(n)
    데이터가 몇번 나왔는지 세어주는 방법이다.
    => 숫자 x 데이터가 들어왔을 때 index[x]의 값을 +1 해주는 방식을 사용했다.

🔎 코드

import sys

n = int(sys.stdin.readline())
index = [0] * 10001
for _ in range(n):
    x = int(sys.stdin.readline())
    index[x] = index[x] + 1

for i in range(10001):
    if index[i] > 0:
        for j in range(index[i]):
            print(i)
profile
초보 개발자

0개의 댓글