思路分析
按题目要求实现即可。注意二维数组的深拷贝操作。
代码实现
class SubrectangleQueries {private int[][] value;public SubrectangleQueries(int[][] rectangle) {value = new int[rectangle.length][];for (int i = 0; i < rectangle.length; ++i) {value[i] = rectangle[i].clone();}}public void updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) {int i, j;for (i = row1; i <= row2; ++i) {for (j = col1; j <= col2; ++j) {value[i][j] = newValue;}}}public int getValue(int row, int col) {return value[row][col];}}/*** Your SubrectangleQueries object will be instantiated and called as such:* SubrectangleQueries obj = new SubrectangleQueries(rectangle);* obj.updateSubrectangle(row1,col1,row2,col2,newValue);* int param_2 = obj.getValue(row,col);*/
