프로그래머스 - 기능개발
fun solution(progresses: IntArray, speeds: IntArray): IntArray {
var count = 0
val queue = progresses.toMutableList()
val speedMutableList = speeds.toMutableList()
val answer = mutableListOf<Int>()
while (queue.isNotEmpty()) {
for (index in queue.indices) {
if (queue[index] >= 100) {
queue[index] = 100
} else {
queue[index] = queue[index].plus(speedMutableList[index])
}
}
for (index in queue.indices) {
if (queue[0] == 100) {
queue.removeAt(0)
speedMutableList.removeAt(0)
count = count.plus(1)
} else {
break
}
}
if (count != 0) {
answer.add(count)
count = 0
}
}
return answer.toIntArray()
}
728x90
최근댓글