๋ฌธ์
์์
ํ์ด
- ํ๋ ฌ ํ์ ๋ก์ง์ ์ธ๋ฑ์ค ํ๋์ฉ ์ด๋ํ๋๋ก ๊ตฌํํ๋ฉด ๋ฉ๋๋ค.
- queies๋ 1๋ถํฐ ์์ํ๋ -1์ ํด์ฃผ์๋ฉด ๋ฉ๋๋ค.
import kotlin.math.*
class Solution {
fun solution(rows: Int, columns: Int, queries: Array<IntArray>): IntArray {
var answer = mutableListOf<Int>()
val arr = Array(rows){ i ->
IntArray(columns){ j -> i*columns + j +1}
}
queries.forEach{
val fy = it[0] -1
val fx = it[1] -1
val sy = it[2] -1
val sx = it[3] -1
val last = arr[fy][fx]
var num = last
(fy..sy-1).forEach{
arr[it][fx] = arr[it+1][fx]
num = min(arr[it][fx], num)
}
(fx..sx-1).forEach{
arr[sy][it] = arr[sy][it+1]
num = min(arr[sy][it], num)
}
(sy downTo fy+1).forEach{
arr[it][sx] = arr[it-1][sx]
num = min(arr[it][sx], num)
}
(sx downTo fx+1).forEach{
arr[fy][it] = arr[fy][it-1]
num = min(arr[fy][it], num)
}
arr[fy][fx+1] = last
answer.add(num)
}
return answer.toIntArray()
}
}
์ฐธ๊ณ
- ํจ์ํ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด์ธ kotlin์ ํน์ฑ์ ๋ง๊ฒ ํจ์๋ฅผ ๋ง์ด ์ตํ์ ๐ฝ