From 60316eacccdf67d63c1ffdc38008272434c64b70 Mon Sep 17 00:00:00 2001 From: Eatswap Date: Thu, 30 Mar 2023 01:54:23 +0800 Subject: [PATCH] add: 230330-CN --- cpp/2303/230330-CN.cpp | 25 +++++++++++++++++++++++++ cpp/2303/CMakeLists.txt | 4 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 cpp/2303/230330-CN.cpp diff --git a/cpp/2303/230330-CN.cpp b/cpp/2303/230330-CN.cpp new file mode 100644 index 0000000..dd329f5 --- /dev/null +++ b/cpp/2303/230330-CN.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include + +/** + * 1637. Widest Vertical Area Between Two Points Containing No Points + * + * Given n points on a 2D plane where points[i] = [xi, yi], Return the widest vertical area between two points such that no points are inside the area. + * A vertical area is an area of fixed-width extending infinitely along the y-axis (i.e., infinite height). The widest vertical area is the one with the maximum width. + * Note that points on the edge of a vertical area are not considered included in the area. + */ + +class Solution { +public: + static auto maxWidthOfVerticalArea(const std::vector>& p) { + std::set v; + std::transform(p.begin(), p.end(), std::inserter(v, v.begin()), [](auto&& x) { return x[0]; }); + auto r = 0; + for (auto i = std::next(v.begin()); i != v.end(); ++i) + r = std::max(r, *i - *std::prev(i)); + return r; + } +}; \ No newline at end of file diff --git a/cpp/2303/CMakeLists.txt b/cpp/2303/CMakeLists.txt index 97131c7..b64bbca 100644 --- a/cpp/2303/CMakeLists.txt +++ b/cpp/2303/CMakeLists.txt @@ -1,6 +1,6 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.26) +CMAKE_MINIMUM_REQUIRED(VERSION 3.24) PROJECT(2303) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2303 230329.cpp) +ADD_EXECUTABLE(2303 230330-CN.cpp)