๊ธ€ ์ž‘์„ฑ์ž: ์ด์ง€์›๐ŸŒฉ๏ธ

๋‹จ์ˆœ๋ฌด์‹ํ•˜๊ฒŒ 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
}
๋ฐ˜์‘ํ˜•