본문 바로가기
코딩공부/프로그래머스 (python)

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

by CodingKwon 2021. 7. 15.

문제 링크 (Level 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

 

나의 코드 (python)

def solution(array, commands):
    answer = []

    for arr in commands:
        step = array[arr[0]-1:arr[1]]
        step.sort()
        answer.append(step[arr[2] - 1])


    return answer

 

이 문제는 배열을 슬라이싱 할 때 범위를 잘 확인해야 합니다.

 

댓글