LeetCode之Subrectangle Queries(Ko

2020-12-14  本文已影响0人  糕冷羊

问题:



方法:
如题意可以暴力解;或者可以记录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

上一篇 下一篇

猜你喜欢

热点阅读