Skip to content

Commit 5a70298

Browse files
authored
Create widest-vertical-area-between-two-points-containing-no-points.cpp
1 parent f46fc65 commit 5a70298

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Time: O(nlogn)
2+
// Space: O(n)
3+
4+
class Solution {
5+
public:
6+
int maxWidthOfVerticalArea(vector<vector<int>>& points) {
7+
set<int> sorted_x;
8+
for (const auto& point : points) {
9+
sorted_x.emplace(point[0]);
10+
}
11+
int result = 0, prev = -1;
12+
for (const auto x : sorted_x) {
13+
if (prev != -1) {
14+
result = max(result, x - prev);
15+
}
16+
prev = x;
17+
}
18+
return result;
19+
}
20+
};

0 commit comments

Comments
 (0)