add: 230326-CN

This commit is contained in:
Eatswap 2023-03-26 18:40:00 +08:00
parent 0bf2639257
commit eedc44ba5c
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
2 changed files with 25 additions and 1 deletions

24
cpp/2303/230326-CN.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <vector>
#include <unordered_set>
/**
* 2395. Find Subarrays With Equal Sum
*
* Given a 0-indexed integer array nums, determine whether there exist two subarrays of length 2 with equal sum. Note that the two subarrays must begin at different indices.
* Return true if these subarrays exist, and false otherwise.
* A subarray is a contiguous non-empty sequence of elements within an array.
*/
class Solution {
public:
static bool findSubarrays(const std::vector<int>& nums) {
const int n = nums.size();
std::unordered_set<int> s;
for (int i = 1; i < n; ++i)
if (s.count(nums[i] + nums[i - 1]))
return true;
else
s.insert(nums[i] + nums[i - 1]);
return false;
}
};

View File

@ -3,4 +3,4 @@ PROJECT(2303)
SET(CMAKE_CXX_STANDARD 23) SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(2303 230325.cpp) ADD_EXECUTABLE(2303 230326-CN.cpp)