I'm trying to find more documentation related to this code
unordered_set<int> s(nums.begin(),nums.end());
but the books i'v been studying, such as
Programming Principles and Practice Using C++ 2nd Edition by Bjarne Stroustrup
C++ Primer
doesn't have much information on unordered_set
i'v tried checking
https://www.learncpp.com/cpp-tutorial/stl-containers-overview/
https://en.cppreference.com/w/cpp/container/unordered_set
but can't find the info i need.
could someone help point me to good resources with details to learn more about this topic?
as of now, i'm trying to understand this line of code specifically...
unordered_set<int> s(nums.begin(),nums.end());
i know what nums.begin() and nums.end() do
but i'm having problem learning more about the syntax
unordered_set<int> s( argument1, argument2 );
and what that does...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
#include <unordered_set>
#include <vector>
using std::cout;
using std::cin;
using std::endl;
using std::unordered_set;
using std::vector;
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
unordered_set<int> s(nums.begin(),nums.end());
return !(s.size()==nums.size());
}
};
int main(){
vector<int> nums={1,3,5,7,9,5};
// int k= 7;
Solution test;
if(test.containsDuplicate(nums))
cout << "true" << endl;
else
cout << "false" << endl;
return 0;
}
|