https://programmers.co.kr/learn/courses/30/lessons/42748?language=scala
object Solution01 extends App {
var array = Vector(1, 5, 2, 6, 3, 7, 4)
var commands = Vector(Vector(2, 5, 3), Vector(4, 4, 1), Vector(1, 7, 3))
def solution(array: Vector[Int], commands: Vector[Vector[Int]]): Vector[Int] = {
def innerSol(array: Vector[Int], command: Vector[Int]): Int = {
var from = command(0) - 1
var to = command(1)
var index = command(2) - 1
return array.slice(from, to).sortWith(_ < _)(index)
}
return commands.map(innerSol(array, _)).collect({ case i: Int => i })
}
solution(array, commands)
}
반응형