- 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/42748

 

Level1 문제이고, 스스로 푼 문제다!

간단한 정렬 문제이고, 주의해야할 점은 문제에서 주어진 인덱스는 실제 인덱스 + 1 이기 때문에 이를 고려해서 

코드를 작성해야 IndexError가 발생하지 않는다 

 

- 정답 풀이 :

def solution(array, commands):
    answer = []
    
    for arr in commands:        
        i,j = arr[0] - 1, arr[1] - 1
        temp = array[i : j + 1]
        temp.sort()
        #문제에서 주어진 인덱스는 다 +1이 되어있으니까 -1 해줘야 IndexError가 발생하지 않음
        answer.append(temp[arr[2] - 1])
        
    return answer

+ Recent posts