Contains Duplicate leetcode

Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.

 

Subscribe to see which companies asked this question

 

bool containsDuplicate(vector<int>& nums) {
    unordered_map<int, int> hash;
    for (auto i : nums)
    {
        if (hash.find(i) == hash.end())
            hash.insert(make_pair(i, 1));
        else
            return true;
    }
    return false;
}

 

posted @ 2016-01-09 16:21  sdlwlxf  阅读(105)  评论(0编辑  收藏  举报