728x90
๋ฐ์ํ
Youtube ํ์ด์์
Problem
Source Code
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
let number = Array(array[i...j]).sorted()[k]
answer.append(number)
}
return answer
}
func solution(_ array:[Int], _ commands:[[Int]]) -> [Int] {
var answer:[Int] = []
commands.forEach {
answer.append(Array(array[$0[0] - 1...$0[1]-1]).sorted()[$0[2]-1])
}
return answer
}
728x90
๋ฐ์ํ
'๐ Problem Solution > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํ๋ก๊ทธ๋๋จธ์ค ๋๋์ด ๋จ์ด์ง๋ ์ซ์ ๋ฐฐ์ด Swift (0) | 2020.02.11 |
---|---|
ํ๋ก๊ทธ๋๋จธ์ค ๊ฐ์ด๋ฐ ๊ธ์ ๊ฐ์ ธ์ค๊ธฐ Swift (0) | 2020.02.09 |
ํ๋ก๊ทธ๋๋จธ์ค 2016๋ Swift (0) | 2020.02.09 |
ํ๋ก๊ทธ๋๋จธ์ค ์ฒด์ก๋ณต Swift (0) | 2020.02.08 |
Swift ํ๋ก๊ทธ๋๋จธ์ค ์ํฌ์ (0) | 2020.02.06 |
๋๊ธ