-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorderOfLargestPlusSign.cpp
More file actions
28 lines (27 loc) · 1.1 KB
/
orderOfLargestPlusSign.cpp
File metadata and controls
28 lines (27 loc) · 1.1 KB
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
class Solution {
public:
int orderOfLargestPlusSign(int n, vector<vector<int>>& mines) {
vector<vector<int>> dp(n, vector<int>(n, n));
for (auto &e : mines) dp[e[0]][e[1]] = 0;
for (int i = 0; i < n; ++i) {
int left = 0, right = 0, up = 0, down = 0;
for (int j = 0, k = n - 1; j < n; ++j, --k) {
left = dp[i][j] ? left + 1 : 0;
right = dp[i][k] ? right + 1 : 0;
up = dp[j][i] ? up + 1 : 0;
down = dp[k][i] ? down + 1 : 0;
dp[i][j] = min(dp[i][j], left);
dp[i][k] = min(dp[i][k], right);
dp[j][i] = min(dp[j][i], up);
dp[k][i] = min(dp[k][i], down);
}
}
int ans = 0;
for (auto& e : dp) ans = max(ans, *max_element(e.begin(), e.end()));
return ans;
}
};
// 作者:ylb
// 链接:https://leetcode.cn/problems/largest-plus-sign/solutions/1958299/by-lcbin-m7yb/
// 来源:力扣(LeetCode)
// 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。