Notice
Recent Posts
Recent Comments
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

No Limitation

[정렬] K 번째 수 - 프로그래머스 본문

프로그래밍

[정렬] K 번째 수 - 프로그래머스

yesungcho 2022. 1. 29. 19:39

https://programmers.co.kr/learn/courses/30/lessons/42748?language=python3 

 

코딩테스트 연습 - K번째수

[1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3]

programmers.co.kr

가볍게 풀어본 구현 연습

def solution(array, commands):
    answer = []; answer = [sorted(array[com[0]-1:com[1]])[com[2]-1] for com in commands ]
    return answer

 

Time complexity

commands element 갯수 → n

for 반복문 → O(n)

축약된 array의 길이 → m

sorted → O(mlogm)

총 시간 복잡도

O(n * mlogm)

 

최종 시간 복잡도

O(n*mlogm)알고리즘