LeetCode:1476 子矩形查询
题目很简单,考察简单构造函数与矩阵边界问题
代码:
class SubrectangleQueries {
private static int[][] rectangle;
public SubrectangleQueries(int[][] rectangle) {
this.rectangle = rectangle;
}
public void updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) {
int i=row1,j=col1;
while(i<=row2&&j<=col2)
{
while(j<=col2)
{
rectangle[i][j]=newValue;
j++;
}
j=col1;
i++;
}
}
public int getValue(int row, int col) {
return rectangle[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);
*/