LeetCode#1476子矩形查询

题目描述

执行结果:通过
执行用时:30 ms, 在所有 Java 提交中击败了95.73%的用户
内存消耗:42.2 MB, 在所有 Java 提交中击败了76.54%的用户

class SubrectangleQueries {
    int[][] rectangle;
    public SubrectangleQueries(int[][] rectangle) {
      this.rectangle = rectangle;
    }
    
    public void updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) {
      for(int i = row1; i <= row2;i++){
        for(int j = col1;j <= col2;j++){
          rectangle[i][j] = newValue;
        }
      }
    }
    
    public int getValue(int row, int col) {
      return rectangle[row][col];    
    }
}

题目很长,理解起来要费些时间。代码逻辑不复杂,嵌套for循环赋值。

欢迎大家来我的 [Gitee仓库](https://gitee.com/jiffyzhang)参观。 同时欢迎关注我的同名公众号:就这样写(keepStarve),未来很大可能会活跃在此地。
原文地址:https://www.cnblogs.com/zhang-bobo/p/13737242.html