Skip to content

Commit e75670c

Browse files
committed
Jan 22
1 parent f75483e commit e75670c

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from collections import deque
2+
from itertools import product
3+
from typing import List
4+
5+
6+
class Solution:
7+
8+
DIRECTIONS = ((0, 1), (-1, 0), (1, 0), (0, -1))
9+
10+
def highestPeak(self, isWater: List[List[int]]) -> List[List[int]]:
11+
m, n = len(isWater), len(isWater[0])
12+
matrix = [[None]*n for _ in range(m)]
13+
queue = deque([])
14+
15+
for x, y in product(range(m), range(n)):
16+
if isWater[x][y]:
17+
matrix[x][y] = 0
18+
queue.append((x, y))
19+
20+
while queue:
21+
x, y = queue.popleft()
22+
for dx, dy in self.DIRECTIONS:
23+
nx, ny = x + dx, y + dy
24+
if 0 <= nx < m and 0 <= ny < n and matrix[nx][ny] is None:
25+
matrix[nx][ny] = matrix[x][y] + 1
26+
queue.append((nx, ny))
27+
return matrix
28+
29+
30+
def main():
31+
isWater = [[0, 1],
32+
[0, 0]]
33+
assert Solution().highestPeak(isWater) == [[1, 0],
34+
[2, 1]]
35+
36+
isWater = [[0, 0, 1],
37+
[1, 0, 0],
38+
[0, 0, 0]]
39+
assert Solution().highestPeak(isWater) == [[1, 1, 0],
40+
[0, 1, 1],
41+
[1, 2, 2]]
42+
43+
44+
if __name__ == '__main__':
45+
main()

2025-01-January-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
| January 19 | [407. Trapping Rain Water II](https://leetcode.com/problems/trapping-rain-water-ii/) | Hard | Unsolved |
2525
| January 20 | [2661. First Completely Painted Row or Column](https://leetcode.com/problems/first-completely-painted-row-or-column/) | Medium | Solved |
2626
| January 21 | [2017. Grid Game](https://leetcode.com/problems/grid-game/) | Medium | Solved |
27-
| January 22 | []() | | |
27+
| January 22 | [1765. Map of Highest Peak](https://leetcode.com/problems/map-of-highest-peak/) | Medium | Solved |
2828
| January 23 | []() | | |
2929
| January 24 | []() | | |
3030
| January 25 | []() | | |
@@ -40,5 +40,5 @@
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
4242
| Easy | 4 | 4 | 0 |
43-
| Medium | 14 | 12 | 2 |
43+
| Medium | 15 | 13 | 2 |
4444
| Hard | 2 | 0 | 2 |

0 commit comments

Comments
 (0)