-
Notifications
You must be signed in to change notification settings - Fork 481
/
1102.cpp
29 lines (29 loc) · 848 Bytes
/
1102.cpp
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
class Solution
{
public:
int maximumMinimumPath(vector<vector<int>>& A)
{
int r = A.size(), c = A[0].size();
vector<vector<int>> vi(r, vector<int>(c, 0));
priority_queue<vector<int>> q;
q.push({A[0][0], 0, 0});
while (!q.empty())
{
auto it = q.top(); q.pop();
if (it[1] == r-1 and it[2] == c-1) return it[0];
for (auto& d : dire)
{
int nx = d[0] + it[1], ny = d[1] + it[2];
if (nx >= 0 and nx < r and ny >= 0 and ny < c
and vi[nx][ny] == 0)
{
vi[nx][ny] = 1;
q.push({min(it[0], A[nx][ny]), nx, ny});
}
}
}
return 0;
}
private:
int dire[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
};