1
2
3
4
5
6
7
8
9
10
11
12
13
| def construct(self, grid: List[List[int]]) -> 'Node':
def dfs(r0: int, r1: int, c0: int,c1: int) -> 'Node':
for i in range(r0, r1):
for j in range(c0, c1):
if grid[i][j] != grid[r0][c0]:
return Node(True,
False,
dfs(r0, r0+r1>>1, c0, c0+c1>>1),
dfs(r0, r0+r1>>1, c0+c1>>1, c1),
dfs(r0+r1>>1, r1, c0, c0+c1>>1),
dfs(r0+r1>>1, r1, c0+c1>>1, c1))
return Node(grid[r0][c0], True)
return dfs(0, len(grid), 0, len(grid[0]))
|