10989번 수 정렬하기 3
풀이 방법
풀이
Python
import sys
n = int(sys.stdin.readline())
counting_list = [0] * 10001
for _ in range(n):
num = int(sys.stdin.readline())
counting_list[num] += 1
for i in range(len(counting_list)):
if counting_list[i] != 0:
for _ in range(counting_list[i]):
print(i)
Swift
- swift로 풀었을 때는 시간초과가 난다
- 나중에 다시 도전
let n = Int(readLine()!)!
var countingArray = Array(repeating: 0, count: 10001)
for _ in 1...n {
let num = Int(readLine()!)!
countingArray[num] += 1
}
for i in 0..<countingArray.count {
if countingArray[i] != 0 {
for _ in 1...countingArray[i] {
print(i)
}
}
}