5
def trapRainWater(self, heightMap: List[List[int]]) -> int:6
ROW, COL = len(heightMap), len(heightMap[0])12
for row in range(ROW):13
for col in range(COL):14
if row == 0 or row == ROW - 1 or col == 0 or col == COL - 1:15
heapq.heappush(pq, (heightMap[row][col], row, col))16
visited[(row, col)] = True21
res.append((row - 1, col))23
res.append((row, col - 1))25
res.append((row + 1, col))27
res.append((row, col + 1))34
h, i, j = heapq.heappop(pq)36
for dx, dy in getnbr(i, j):37
if (dx, dy) not in visited:39
res += max(0, h - heightMap[dx][dy])41
heapq.heappush(pq, (max(h, heightMap[dx][dy]), dx, dy))42
visited[(dx, dy)] = True