STUDYING/Algorithm
[Programmers] K번째 수
EOZIN
2021. 9. 27. 00:33
728x90
https://programmers.co.kr/learn/courses/30/lessons/42748
import Foundation
func solution(_ array:[Int], _ commands:[[Int]]) -> [Int] {
var res = [Int]()
for i in 0..<commands.count {
let start = commands[i][0] - 1
let end = commands[i][1] - 1
let num = commands[i][2] - 1
var tmp = [Int]()
for j in start...end {
tmp.append(array[j])
}
tmp.sort()
res.append(tmp[num])
}
return res
}