거북이개발자

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

Algorithm(Python)/programmers(Lv.1)

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

류정식 2021. 6. 23. 13:21

0. 제목

  • 프로그래머스 K번째수

1. 문제

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

 


 

2. 풀이

  • 리스트의 [:] 성질만 이용하면 어렵지 않다.
  •  

 

 

 


3. 코드

(1). 내적

def solution(array, commands):
    array_sliced=[]
    answer = []
    
    for i in commands:
        array_sliced=array[i[0]-1 : i[1]]
        array_sliced.sort()
        answer.append(array_sliced[i[2]-1])
      
    return answer
Comments