문제링크 :https://programmers.co.kr/learn/courses/30/lessons/42748
코딩테스트 연습 - K번째수
[1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3]
programmers.co.kr
문제설명
배열 array, [i, j, k]를 원소로 가진 2차원 배열 commands가 매개변수로 주어질 때, commands의 모든 원소에 대해 앞서 설명한 연산을 적용했을 때 나온 결과를 배열에 담아 return 하는 solution 함수
알고리즘
1.그냥 주어진 범위로 자른후 정렬하고 해당 idx를 출력하면된다 .
코드
1 2 3 4 5 6 7 8 9 10 | # k번째 수 def solution(array, commands): answer = [] for idx in range(len(commands)): test = array[commands[idx][0]-1:commands[idx][1]] test= sorted(test) answer.append(test[commands[idx][2]-1]) return answer | cs |
'파이썬 > 프로그래머스' 카테고리의 다른 글
[python] 프로그래머스 - H-index (0) | 2020.08.05 |
---|---|
[python ] 프로그래머스 - 가장 큰 수 (0) | 2020.08.05 |
[python] 프로그래머스 - 프린터 (0) | 2020.08.05 |
[python] 프로그래머스 - 다리를 지나는 트럭 (0) | 2020.08.05 |
[python] 프로그래머스 - 오픈 채팅방 (0) | 2020.08.04 |