diff --git a/cpp/2303/230331-CN.cpp b/cpp/2303/230331-CN.cpp new file mode 100644 index 0000000..f6f74a5 --- /dev/null +++ b/cpp/2303/230331-CN.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +/** + * 2367. Number of Arithmetic Triplets + * + * You are given a 0-indexed, strictly increasing integer array nums and a positive integer diff. A triplet (i, j, k) is an arithmetic triplet if the following conditions are met: + * + * i < j < k, + * nums[j] - nums[i] == diff, and + * nums[k] - nums[j] == diff. + * Return the number of unique arithmetic triplets. + */ + +class Solution { +public: + static int arithmeticTriplets(const std::vector& nums, int diff) { + std::unordered_set s(nums.begin(), nums.end()); + return std::count_if(nums.begin(), nums.end(), [&](int x) { + return s.count(x + diff) && s.count(x + 2 * diff); + }); + } +}; diff --git a/cpp/2303/CMakeLists.txt b/cpp/2303/CMakeLists.txt index b64bbca..640f7d2 100644 --- a/cpp/2303/CMakeLists.txt +++ b/cpp/2303/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2303) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2303 230330-CN.cpp) +ADD_EXECUTABLE(2303 230331-CN.cpp)