프로그래머스/Lv.1
[Python] 프로그래머스 K번째수
MINU.SHINNNN
2024. 8. 13. 00:03
https://school.programmers.co.kr/learn/courses/30/lessons/42748
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
sorted와 리스트 인덱싱을 사용해 답을 구할 수 있습니다.
for문을 map함수로 대체하면 한줄로 답을 구할 수 있습니다.
def solution(array, commands):
answer = []
#for idx, command in enumerate(commands):
#answer.append(sorted(array[command[0]-1:command[1]])[command[2]-1])
return list(map(lambda x : sorted(array[x[0]-1:x[1]])[x[2]-1], commands))
#return answer