LeetCode之Subrectangle Queries(Kotlin)

224 阅读1分钟

问题:


方法: 如题意可以暴力解;或者可以记录update操作,然后getValue时推导结果。

class SubrectangleQueries(val rectangle: Array<IntArray>) {
    fun updateSubrectangle(row1: Int, col1: Int, row2: Int, col2: Int, newValue: Int) {
        for (row in row1..row2) {
            for (col in col1..col2) {
                rectangle[row][col] = newValue
            }
        }
    }

    fun getValue(row: Int, col: Int): Int {
        return rectangle[row][col]
    }
}


fun main() {

}

有问题随时沟通

具体代码实现可以参考Github