๐๊ณต๋ถ/์ฝ๋ฉํ
์คํธ
ํ๋ก๊ทธ๋๋จธ์ค - K๋ฒ์งธ์, ํ์ด์ฌ
Janger
2021. 11. 15. 09:33
728x90
https://programmers.co.kr/learn/courses/30/lessons/42748?language=python3
์ฝ๋ฉํ ์คํธ ์ฐ์ต - 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 = []
# 1 5 2 6 3 7 4
# [2 5 3] [4 4 1] [1 7 3]
for i in commands:
print(i[0], i[1], i[2],)
tmp = list( array[i[0]-1:i[1]] )
tmp.sort()
answer.append( tmp[ i[2]-1 ] )
return answer
์ฐ์ ๋ฌธ์ ๋ฅผ ํ์ ํด์ผํ๋๋ฐ ๊ธ์จ๋ง ๋ด์ ์ ์ดํด๊ฐ ์๋์ง๋ง, ์น์ ํ๊ฒ๋ ์๋์ ์ ์ถ๋ ฅ ์๊ฐ ๋์ ์์์
์ ์ถ๋ ฅ ์๋ฅผ ์ง์ค์ ์ผ๋ก ๋ด์ ์ด๋ค ๊ฒฐ๊ณผ๋ฅผ ์ํ๋์ง๋ฅผ ํ์ ํ๊ณ ,
๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด์๋ ์ ๋ ฌ ๋ฉ์๋๊ฐ ํ์ํ๋ค๋ ๊ฒ์ ๊ธฐ์ต์ ํ๊ณ ,
๋ฆฌ์คํธ์ ์ํ๋ ๋ถ๋ถ์ ์๋ฅด๋ ๊ฒ์ ํ์ด์ฌ์ ์ฌ๋ผ์ด์ฑ ๋ฌธ๋ฒ์ ์ด์ฉํ์๋ค.
728x90