执行结果:通过
执行用时: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循环赋值。