Rijkstra的专栏

https://github.com/Ray137076517

【leetcode】Contains Duplicate

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.

class Solution {
public:
    bool containsDuplicate(vector<int>& nums) {
        map<int, int> tmp;
        for (int i = 0; i != nums.size(); ++i)
        {
            if (!((tmp.insert(pair<int, int>(nums[i], i))).second))
                return true;
        }
        return false;
    }
};


Personal Note:

就当复习下map了……

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/C_Ray/article/details/49934389
个人分类: 练习 C++ 算法
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

【leetcode】Contains Duplicate

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭