Class Solution
-
- All Implemented Interfaces:
public final class Solution
2536 - Increment Submatrices by One\.
Medium
You are given a positive integer
n
, indicating that we initially have ann x n
0-indexed integer matrixmat
filled with zeroes.You are also given a 2D integer array
query
. For each <code>queryi = row1<sub>i</sub>, col1<sub>i</sub>, row2<sub>i</sub>, col2<sub>i</sub></code>, you should do the following operation:Add
1
to every element in the submatrix with the top left corner <code>(row1<sub>i</sub>, col1<sub>i</sub>)</code> and the bottom right corner <code>(row2<sub>i</sub>, col2<sub>i</sub>)</code>. That is, add1
tomat[x][y]
for all <code>row1<sub>i</sub><= x <= row2<sub>i</sub></code> and <code>col1<sub>i</sub><= y <= col2<sub>i</sub></code>.
Return the matrix
mat
after performing every query.Example 1:
Input: n = 3, queries = \[\[1,1,2,2],0,0,1,1]
Output: [1,1,0,1,2,1,0,1,1]
Explanation: The diagram above shows the initial matrix, the matrix after the first query, and the matrix after the second query.
In the first query, we add 1 to every element in the submatrix with the top left corner (1, 1) and bottom right corner (2, 2).
In the second query, we add 1 to every element in the submatrix with the top left corner (0, 0) and bottom right corner (1, 1).
Example 2:
Input: n = 2, queries = \[\[0,0,1,1]]
Output: [1,1,1,1]
Explanation: The diagram above shows the initial matrix and the matrix after the first query.
In the first query we add 1 to every element in the matrix.
Constraints:
1 <= n <= 500
<code>1 <= queries.length <= 10<sup>4</sup></code>
<code>0 <= row1<sub>i</sub><= row2<sub>i</sub>< n</code>
<code>0 <= col1<sub>i</sub><= col2<sub>i</sub>< n</code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-