Skip to content

Commit 7891e9b

Browse files
committed
2019-06-30
1 parent 1476880 commit 7891e9b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class Solution(object):
2+
def maximumMinimumPath(self, A):
3+
"""
4+
:type A: List[List[int]]
5+
:rtype: int
6+
"""
7+
from heapq import *
8+
if not A or not A[0]:
9+
return 0
10+
11+
m, n = len(A), len(A[0])
12+
dx = [1, -1, 0, 0]
13+
dy = [0, 0, 1, -1]
14+
15+
res = 0
16+
queue = [[-A[0][0], 0, 0]]
17+
visited = set([0,0])
18+
heapify(queue)
19+
while queue:
20+
val, x0, y0 = heappop(queue) #把目前队里最大的点找出来
21+
if [x0, y0] == [m - 1, n - 1]: #如果已经到终点了
22+
return -val
23+
24+
for k in range(4):
25+
x = x0 + dx[k]
26+
y = y0 + dy[k]
27+
28+
if 0 <= x < m and 0 <= y < n and (x, y) not in visited:
29+
visited.add((x, y))
30+
heappush(queue, [max(val, -A[x][y]), x, y]) #邻居入队
31+
32+
33+

0 commit comments

Comments
 (0)