0%

1762. Buildings With an Ocean View

O(n) time O(n) space

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public:
vector<int> findBuildings(vector<int>& heights) {
vector<int> res;
for (int n = size(heights), i = 0; i < n; ++i) {
while (!empty(res) && heights[res.back()] <= heights[i]) {
res.pop_back();
}
res.push_back(i);
}
return res;
}
};