Skip to content

Commit af1a80d

Browse files
committed
Runtime: 344 ms (Top 99.56%) | Memory: 108.2 MB (Top 83.84%)
1 parent 3ddd820 commit af1a80d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

scripts/algorithms/M/Map of Highest Peak/Map of Highest Peak.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
// Runtime: 344 ms (Top 99.56%) | Memory: 108.2 MB (Top 83.84%)
12
class Solution {
23
public:
34

45
vector<vector<int>> highestPeak(vector<vector<int>>& isWater) {
56
int r = isWater.size();
67
int c = isWater[0].size();
78
queue <pair<int,int>> curr;
8-
9+
910
for (int i = 0; i < r; i++) {
1011
for (int j = 0; j < c; j++) {
1112
//set the land cell to -1 (not visited)
@@ -19,18 +20,18 @@ class Solution {
1920
}
2021
}
2122
}
22-
23+
2324
int hill = 0;
2425
while (!curr.empty()) {
2526
int len = curr.size();
26-
27+
2728
for (int k = 0; k < len; k++) {
28-
29+
2930
//for each cell check its 4 boundary cells
3031
//if it is not visited, increase its hill by 1
3132
pair <int, int> fnt = curr.front(); curr.pop();
3233
int i = fnt.first, j = fnt.second;
33-
34+
3435
//top cell
3536
if (i > 0 && isWater[i - 1][j] == -1) {
3637
isWater[i - 1][j] = hill + 1;
@@ -52,11 +53,11 @@ class Solution {
5253
curr.push({i, j+1});
5354
}
5455
}
55-
56+
5657
//after 1 complete round increase the height of the hill
5758
hill += 1;
5859
}
59-
60+
6061
return isWater;
6162
}
6263
};

0 commit comments

Comments
 (0)