diff --git a/2202/220206-CN.cpp b/2202/220206-CN.cpp new file mode 100644 index 0000000..4691094 --- /dev/null +++ b/2202/220206-CN.cpp @@ -0,0 +1,32 @@ +#include +#include + +/** + * 1748. Sum of Unique Elements + * You are given an integer array nums. The unique elements of an array are the elements that appear exactly once in the array. + * Return the sum of all the unique elements of nums. + */ + +class Solution { +public: + static int sumOfUnique(const std::vector& nums) { + int ans = 0; + std::unordered_multiset s; + for (int x : nums) { + switch (s.count(x)) { + case 0: + ans += x; + break; + case 1: + ans -= x; + } + s.insert(x); + } + return ans; + } +}; + +int main() { + // No testing code. + return 0; +} diff --git a/2202/CMakeLists.txt b/2202/CMakeLists.txt index 90d22c9..3c7ae1d 100644 --- a/2202/CMakeLists.txt +++ b/2202/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2202) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2202 220205.cpp) +ADD_EXECUTABLE(2202 220206-CN.cpp)