美文网首页
LeetCode之Subrectangle Queries(Ko

LeetCode之Subrectangle Queries(Ko

作者: 糕冷羊 | 来源:发表于2020-12-14 15:00 被阅读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

相关文章

网友评论

      本文标题:LeetCode之Subrectangle Queries(Ko

      本文链接:https://www.haomeiwen.com/subject/qlmvgktx.html