๋จ์๋ฌด์ํ๊ฒ commands
๋ฐฐ์ด ์ํํ๋ฉด์ ์๊ตฌ ์ฌํญ๋๋ก ๋ง์ถฐ์ ์ฝ๋ฉํ๋ค. ์์ ์ ํ์๋ ํ์ด์ฌ ์ฝ๋๋ฅผ ๋ณด๋ฉด ์์ฒญ ๊ฐ๊ฒฐํ๊ฒ ํด๋จ๋๋ฐ, ์ค์ํํธ๋ก๋ ๊ทธ๋ ๊ฒ ๊ตฌํํ๋ ค๋ฉด subscript
๋ฅผ ๊ตฌํํ๋ฉด ๋ ๊ฑฐ ๊ฐ์๋ฐ ์ผ๋จ์ ํจ์ค.
๋ฌธ์
https://programmers.co.kr/learn/courses/30/lessons/42748?language=swift
๋ด๊ฐ ์์ฑํ ์ฝ๋
Swift
import Foundation
func solution(_ array:[Int], _ commands:[[Int]]) -> [Int] {
var answer = [Int]()
for command in commands {
let i = command[0]-1
let j = command[1]-1
let k = command[2]-1
var arr = [Int]()
for a in i...j {
arr.append(array[a])
}
answer.append(arr.sorted()[k])
}
return answer
}