문제 링크 (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
이 문제는 배열을 슬라이싱 할 때 범위를 잘 확인해야 합니다.
'코딩공부 > 프로그래머스 (python)' 카테고리의 다른 글
[프로그래머스] 소수 만들기 (python) (0) | 2021.07.16 |
---|---|
[프로그래머스] 크레인 인형뽑기 (python) (0) | 2021.07.16 |
[프로그래머스] 음양 더하기 (python) (0) | 2021.07.15 |
[프로그래머스] 내적 (python) (0) | 2021.07.15 |
[프로그래머스] 신규 아이디 추천 (python) (0) | 2021.07.15 |
댓글