LeetCode Contains Duplicate

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.

 

  题目大意:给你一个int型数组,看看这个数组是否包含重复的数字,如果包含返回true,否则返回false

建立一个map即可!

 

class Solution {
public:
    bool containsDuplicate(vector<int>& nums) {
        map<int, int> iiMap;
        for (auto &e : nums)
            {
                if(++iiMap[e]>1)return true;
            }
        return false;
    }
};

 

以上是关于LeetCode Contains Duplicate的主要内容,如果未能解决你的问题,请参考以下文章

leetcode笔记:Contains Duplicate III

LeetCode-Contains Duplicate

LeetCode219. Contains Duplicate II

LeetCode Contains Duplicate

LeetCode 217. Contains Duplicate

LeetCode 217 Contains Duplicate