나의 풀이
def solution(array, commands):
answer = []
array.insert(0,0)
for com in commands:
start, end, nd =com[0], com[1], com[2]
array2=array[start:end+1:]
array2.sort()
array2.insert(0,0)
# print(array2)
answer.append(array2[nd])
# print(answer)
return answer
▶ 1차원 리스트의 각 요소를 각각의 변수로 받을 수 있다.★★
다른 사람의 풀이1
def solution(array, commands):
result = []
for command in commands:
i, j, k = command
result.append(sorted(array[i-1:j])[k-1])
return result
▶ 1차원 리스트의 각 요소를 각각의 변수로 받을 수 있다.★★
다른 사람의 풀이2
def solution(array, commands):
result = []
for command in commands:
i, j, k = command[0], command[1], command[2]
subarray = sorted(array[i-1:j])
result.append(subarray[k-1])
return result
▶ 1차원 리스트의 각 요소를 각각의 변수로 받을 수 있다.★★
'프로그래머스(파이썬) > LV.1(파이썬)' 카테고리의 다른 글
삼총사→ 조합 + 삼중 for문 (0) | 2022.12.17 |
---|---|
숫자 문자열과 영단어(카카오) →replace(), for문을 이용한 dictionary()★ (0) | 2022.12.17 |
문자열 내 마음대로 정렬하기→특이한 정렬과 유사★ (0) | 2022.12.17 |
[1차] 비밀지도→ OR연산 + rjust(자릿수, 숫자)★★ (0) | 2022.12.17 |
최소직사각형→a,b의 교환, for a, b in sizes 행마다 각각 요소접근★★ (0) | 2022.12.16 |