add: 220521-CN [cpp]
This commit is contained in:
parent
0969951471
commit
3a3cc21bb2
|
|
@ -0,0 +1,24 @@
|
|||
#include <vector>
|
||||
#include <unordered_set>
|
||||
|
||||
/**
|
||||
* 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<int>& nums) {
|
||||
std::unordered_set<int> s;
|
||||
for (int i : nums) {
|
||||
if (s.count(i))
|
||||
return i;
|
||||
s.insert(i);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
|
@ -3,4 +3,4 @@ PROJECT(2205)
|
|||
|
||||
SET(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
ADD_EXECUTABLE(2205 220521.cpp)
|
||||
ADD_EXECUTABLE(2205 220521-CN.cpp)
|
||||
|
|
|
|||
Loading…
Reference in New Issue