-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy path3537-fill-a-special-grid.py
More file actions
31 lines (26 loc) · 902 Bytes
/
3537-fill-a-special-grid.py
File metadata and controls
31 lines (26 loc) · 902 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
26
27
28
29
30
31
# time complexity: O(m*n)
# space complexity: O(m*n)
from typing import List
class Solution:
def specialGrid(self, N: int) -> List[List[int]]:
def build(num):
if num == 0:
return [[0]]
ROW = COL = 2 ** (num - 1)
prevMatrix = build(num - 1)
curr = [[0 for _ in range(2 * COL)] for _ in range(2 * ROW)]
for r in range(ROW):
for c in range(COL):
val = prevMatrix[r][c]
curr[r][c + COL] = val + 0 * ROW * COL
curr[r + ROW][c + COL] = val + 1 * ROW * COL
curr[r + ROW][c] = val + 2 * ROW * COL
curr[r][c] = val + 3 * ROW * COL
return curr
return build(N)
N = 0
print(Solution().specialGrid((N)))
N = 1
print(Solution().specialGrid((N)))
N = 2
print(Solution().specialGrid((N)))