diff --git a/cpp/2205/220521-CN.cpp b/cpp/2205/220521-CN.cpp new file mode 100644 index 0000000..7fd685c --- /dev/null +++ b/cpp/2205/220521-CN.cpp @@ -0,0 +1,24 @@ +#include +#include + +/** + * 961. N-Repeated Element in Size 2N Array + * You are given an integer array nums with the following properties: + * - nums.length == 2 * n. + * - nums contains n + 1 unique elements. + * - Exactly one element of nums is repeated n times. + * Return the element that is repeated n times. + */ + +class Solution { +public: + static int repeatedNTimes(const std::vector& nums) { + std::unordered_set s; + for (int i : nums) { + if (s.count(i)) + return i; + s.insert(i); + } + return -1; + } +}; diff --git a/cpp/2205/CMakeLists.txt b/cpp/2205/CMakeLists.txt index 119a00a..15e1b64 100644 --- a/cpp/2205/CMakeLists.txt +++ b/cpp/2205/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2205) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2205 220521.cpp) +ADD_EXECUTABLE(2205 220521-CN.cpp)