Skip to content

Commit e6b6a96

Browse files
committed
Runtime: 20 ms (Top 84.0%) | Memory: 56.70 MB (Top 5.33%)
1 parent 340be65 commit e6b6a96

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Runtime: 20 ms (Top 84.0%) | Memory: 56.70 MB (Top 5.33%)
2+
3+
class Solution {
4+
public int[][] rangeAddQueries(int n, int[][] queries) {
5+
int[][] res = new int[n][n];
6+
for (var q : queries) {
7+
int r0 = q[0], c0 = q[1], r1 = q[2]+1, c1 = q[3]+1;
8+
for (int i = r0; i < r1; i++) {
9+
res[i][c0]++;
10+
if (c1 < n) res[i][c1]--;
11+
}
12+
}
13+
14+
for (var row : res)
15+
for (int j = 1; j < n; j++)
16+
row[j] += row[j-1];
17+
18+
return res;
19+
}
20+
}

0 commit comments

Comments
 (0)