Algorithm/Learning

[Algo] 정렬 문제풀이 3

앵도라지 2023. 2. 22. 11:02

계수 정렬

array = [7, 5, 9, 0, 3, 1, 6, 2, 4, 8]
​
count = [0] * (max(array) + 1)
​
for i in range(len(array)):
  count[array[i]] += 1for i in range(len(count)):
  for j in range(count[i]):
    print(i, end=' ')

프로그래머스 K번째 수

def solution(array, commands):
    answer = []
    for a in range(len(commands)):
        i = commands[a][0]
        j = commands[a][1]
        k = commands[a][2]
        temp = array[i-1:j]
        temp.sort()
        answer.append(temp[k-1])
    return answer

백준 16435 스네이크버드

n, m = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
for i in arr : 
    if i <= m: 
        m += 1
print(m)