Contains Duplicates (Hashmap)
Note:
This code was written during a crunch period and isn't perfect. There will
be some errant spacing, some files will be
using namespace std,
etc. But it's all still usable and can be a
handy guideline if you're learning Data Structures.
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
bool containsDuplicates(std::vector<int> numbers)
{
std::map<int, bool> entries;
for (int x : numbers)
{
if (entries[x])
return true;
entries[x] = true;
}
return false;
}
int main(int argc, char *argv[])
{
if (containsDuplicates(nums))
{
std::cout << "Found Dupe" << std::endl;
}
else
{
std::cout << "No Dupe" << std::endl;
}
if (containsDuplicates(nuNums))
{
std::cout << "Found Dupe" << std::endl;
}
else
{
std::cout << "No Dupe" << std::endl;
}
}