class SubrectangleQueries {
public:
vector<vector<int>> rect;
SubrectangleQueries(vector<vector<int>>& rectangle) {
rect=rectangle;//值得注意的是rect并不是一个矩阵对象的引用
}
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++)
{
rect[i][j]=newValue;
}
}
}
int getValue(int row, int col) {
return rect[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);
*/
LeetCode:1476. 子矩形查询
最新推荐文章于 2023-02-22 23:32:34 发布