mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-12 17:20:29 +01:00
cpp: add “1637. Widest Vertical Area Between Two Points Containing No Points”
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
57a9ddef6f
commit
c2916fdf5f
1 changed files with 21 additions and 0 deletions
|
@ -0,0 +1,21 @@
|
||||||
|
#include <algorithm>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
int maxWidthOfVerticalArea(const std::vector<std::vector<int>>& points) {
|
||||||
|
std::set<int> seen;
|
||||||
|
for (const auto& point : points) {
|
||||||
|
seen.insert(point[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int last = *seen.begin();
|
||||||
|
int max_width = 0;
|
||||||
|
for (const auto x : seen) {
|
||||||
|
max_width = std::max(max_width, x - last);
|
||||||
|
last = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
return max_width;
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in a new issue