Skip to content

Commit 0cc03dc

Browse files
authored
Create 2373. Largest Local Values in a Matrix (#476)
2 parents e3a7261 + 29a84c0 commit 0cc03dc

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public:
3+
vector<vector<int>> largestLocal(vector<vector<int>>& grid) {
4+
int n = grid.size();
5+
6+
for(int i = 1; i < n - 1; ++i) {
7+
for(int j = 1; j < n - 1; ++j) {
8+
int temp = 0;
9+
10+
for(int k = i - 1; k <= i + 1; ++k) {
11+
for(int l = j - 1; l <= j + 1; ++l) {
12+
temp = max(temp, grid[k][l]);
13+
}
14+
}
15+
16+
grid[i - 1][j - 1] = temp;
17+
}
18+
}
19+
20+
grid.resize(n - 2);
21+
for (int i = 0; i < grid.size(); ++i) {
22+
grid[i].resize(n - 2);
23+
}
24+
25+
return grid;
26+
}
27+
};

0 commit comments

Comments
 (0)