Skip to content

Commit 855953f

Browse files
add 1476
1 parent e81ab85 commit 855953f

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11-
|1476|[Final Prices With a Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1476.java) | |Easy|Array|
11+
|1476|[Subrectangle Queries](https://leetcode.com/problems/subrectangle-queries/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1476.java) | |Medium|Array|
12+
|1475|[Final Prices With a Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1475.java) | |Easy|Array|
1213
|1471|[The k Strongest Values in an Array](https://leetcode.com/problems/the-k-strongest-values-in-an-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1471.java) | |Medium|Array, Sort|
1314
|1470|[Shuffle the Array](https://leetcode.com/problems/shuffle-the-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1470.java) | |Easy|Array|
1415
|1466|[Reorder Routes to Make All Paths Lead to the City Zero](https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1466.java) | |Medium|Tree, DFS|
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1476 {
4+
public static class Solution1 {
5+
public static class SubrectangleQueries {
6+
int[][] matrix;
7+
int m;
8+
int n;
9+
10+
public SubrectangleQueries(int[][] rectangle) {
11+
m = rectangle.length;
12+
n = rectangle[0].length;
13+
matrix = rectangle;
14+
}
15+
16+
public void updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) {
17+
for (int i = row1; i <= row2; i++) {
18+
for (int j = col1; j <= col2; j++) {
19+
matrix[i][j] = newValue;
20+
}
21+
}
22+
}
23+
24+
public int getValue(int row, int col) {
25+
return matrix[row][col];
26+
}
27+
}
28+
}
29+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1476;
4+
import org.junit.Test;
5+
6+
import static junit.framework.TestCase.assertEquals;
7+
8+
public class _1476Test {
9+
private static _1476.Solution1.SubrectangleQueries solution1;
10+
private static int[][] rectangle;
11+
12+
@Test
13+
public void test1() {
14+
rectangle = new int[][]{
15+
{1, 2, 1},
16+
{4, 3, 4},
17+
{3, 2, 1},
18+
{1, 1, 1}
19+
};
20+
solution1 = new _1476.Solution1.SubrectangleQueries(rectangle);
21+
assertEquals(1, solution1.getValue(0, 2));
22+
solution1.updateSubrectangle(0, 0, 3, 2, 5);
23+
assertEquals(5, solution1.getValue(0, 2));
24+
}
25+
26+
}

0 commit comments

Comments
 (0)