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
def solution(array, commands):
answer = []
#command[0]-1 : slice start
#command[1] : slice end
#command[2]-1 : index
for command in commands:
answer.append(sorted(array[command[0]-1:command[1]])[command[2]-1])
return answer
2021.09.29
def solution(array, commands):
ans = []
for command in commands:
i = command[0]
j = command[1]
k = command[2]
new_array = sorted(array[i-1:j])
ans.append(new_array[k-1])
return ans
아무것도 안보고 푼거라 뿌듯했는데 역시 고수님의 풀이는 다른다.
sort함수를 한 번 정리해야겠다.
'Algorithm > 프로그래머스' 카테고리의 다른 글
[프로그래머스] [Python] Level3_네트워크 (0) | 2021.10.02 |
---|---|
[프로그래머스] [Python] Level2_조이스틱 (0) | 2021.10.02 |
[프로그래머스] [Python] Level2_타겟 넘버 (0) | 2021.08.05 |
[프로그래머스] [Python] Level3_디스크 컨트롤러 (0) | 2021.08.05 |
[프로그래머스] [Python] Level2_주식가격 (0) | 2021.08.05 |
댓글