IT/알고리즘
[프로그래머스] 덧칠하기
남갯
2024. 10. 21. 19:42
SMALL
https://school.programmers.co.kr/learn/courses/30/lessons/161989
fun solution(n: Int, m: Int, section: IntArray): Int {
var answer = 0
val paint = IntArray(n)
for (s in section) {
paint[s - 1] = 1
}
var i = 0
while (i < paint.size) {
if (paint[i] == 1) {
for (j in 0 until m) {
if (i + j < paint.size) {
paint[i + j] = 0
}
}
i = i + m - 1
answer++
}
i++
}
return answer
}
LIST