add: 220206-CN
This commit is contained in:
parent
078e3a226c
commit
70c097ca7e
|
|
@ -0,0 +1,32 @@
|
|||
#include <vector>
|
||||
#include <unordered_set>
|
||||
|
||||
/**
|
||||
* 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<int>& nums) {
|
||||
int ans = 0;
|
||||
std::unordered_multiset<int> 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;
|
||||
}
|
||||
|
|
@ -3,4 +3,4 @@ PROJECT(2202)
|
|||
|
||||
SET(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
ADD_EXECUTABLE(2202 220205.cpp)
|
||||
ADD_EXECUTABLE(2202 220206-CN.cpp)
|
||||
|
|
|
|||
Loading…
Reference in New Issue