Skip to content

Commit e2ca5ae

Browse files
committed
Add solution #1476
1 parent d8dcb4d commit e2ca5ae

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,319 LeetCode solutions in JavaScript
1+
# 1,320 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1128,6 +1128,7 @@
11281128
1472|[Design Browser History](./solutions/1472-design-browser-history.js)|Medium|
11291129
1473|[Paint House III](./solutions/1473-paint-house-iii.js)|Hard|
11301130
1475|[Final Prices With a Special Discount in a Shop](./solutions/1475-final-prices-with-a-special-discount-in-a-shop.js)|Easy|
1131+
1476|[Subrectangle Queries](./solutions/1476-subrectangle-queries.js)|Medium|
11311132
1480|[Running Sum of 1d Array](./solutions/1480-running-sum-of-1d-array.js)|Easy|
11321133
1481|[Least Number of Unique Integers after K Removals](./solutions/1481-least-number-of-unique-integers-after-k-removals.js)|Medium|
11331134
1486|[XOR Operation in an Array](./solutions/1486-xor-operation-in-an-array.js)|Easy|
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* 1476. Subrectangle Queries
3+
* https://leetcode.com/problems/subrectangle-queries/
4+
* Difficulty: Medium
5+
*
6+
* Implement the class SubrectangleQueries which receives a rows x cols rectangle as a matrix
7+
* of integers in the constructor and supports two methods:
8+
* 1. updateSubrectangle(int row1, int col1, int row2, int col2, int newValue)
9+
* - Updates all values with newValue in the subrectangle whose upper left coordinate is
10+
* (row1,col1) and bottom right coordinate is (row2,col2).
11+
* 2. getValue(int row, int col)
12+
*
13+
* Returns the current value of the coordinate (row,col) from the rectangle.
14+
*/
15+
16+
/**
17+
* @param {number[][]} rectangle
18+
*/
19+
var SubrectangleQueries = function(rectangle) {
20+
this.grid = rectangle.map(row => [...row]);
21+
};
22+
23+
/**
24+
* @param {number} row1
25+
* @param {number} col1
26+
* @param {number} row2
27+
* @param {number} col2
28+
* @param {number} newValue
29+
* @return {void}
30+
*/
31+
SubrectangleQueries.prototype.updateSubrectangle = function(row1, col1, row2, col2, newValue) {
32+
for (let i = row1; i <= row2; i++) {
33+
for (let j = col1; j <= col2; j++) {
34+
this.grid[i][j] = newValue;
35+
}
36+
}
37+
};
38+
39+
/**
40+
* @param {number} row
41+
* @param {number} col
42+
* @return {number}
43+
*/
44+
SubrectangleQueries.prototype.getValue = function(row, col) {
45+
return this.grid[row][col];
46+
};

0 commit comments

Comments
 (0)