-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay 39
More file actions
25 lines (19 loc) · 736 Bytes
/
Day 39
File metadata and controls
25 lines (19 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#2536.increment-submatrices-by-one:-
class Solution:
def rangeAddQueries(self, n: int, queries: List[List[int]]) -> List[List[int]]:
diff = [[0] * (n + 1) for _ in range(n + 1)]
for r1, c1, r2, c2 in queries:
diff[r1][c1] += 1
if c2 + 1 < n:
diff[r1][c2 + 1] -= 1
if r2 + 1 < n:
diff[r2 + 1][c1] -= 1
if r2 + 1 < n and c2 + 1 < n:
diff[r2 + 1][c2 + 1] += 1
for i in range(n):
for j in range(1, n):
diff[i][j] += diff[i][j - 1]
for j in range(n):
for i in range(1, n):
diff[i][j] += diff[i - 1][j]
return [row[:n] for row in diff[:n]]