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. 子矩形查询
最新推荐文章于 2021-11-04 21:48:54 发布
本文介绍了一个使用C++实现的矩形更新查询类,该类能够接收一个二维整数数组作为输入,并提供更新子矩形区域值及获取指定位置值的功能。通过实例化该类并调用其成员函数,可以高效地对矩形区域进行批量更新和查询。
2265

被折叠的 条评论
为什么被折叠?



