티스토리 뷰

728x90
반응형

 

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 = []
    for i in range(len(commands)):
        temp = array[commands[i][0]-1:commands[i][1]]
        temp.sort()
        answer.append(temp[commands[i][2]-1])
        
    return answer

 

인덱싱을 이용해서 푼 문제!

 

 

 

 

<다른 사람의 풀이>

def solution(array, commands):
    return list(map(lambda x:sorted(array[x[0]-1:x[1]])[x[2]-1], commands))
    
    
# <배운점> 
# => map과 lambda를 이용하여 짧게 짠 것
728x90
반응형
댓글