首页 > 编程语言 > 详细

leetCode 217. Contains Duplicate 数组

时间:2016-08-12 06:46:15      阅读:264      评论:0      收藏:0      [点我收藏+]

217. 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.

题目大意:

在数组中找到任意字符出现次数大于等于2次就返回true,如果数组中每一个字符都出现1次,则返回false。

代码如下:

class Solution {
public:
    bool containsDuplicate(vector<int>& nums) {
        unordered_map<int,int> myMap;
        for(int i = 0;i < nums.size();i++)
        {
            if(myMap.find(nums[i]) == myMap.end() )
            {
                myMap.insert(pair<int,int>(nums[i],1));
            }
            else
                return true;
        }
        return false;
    }
};

2016-08-12 01:36:29

本文出自 “做最好的自己” 博客,请务必保留此出处http://qiaopeng688.blog.51cto.com/3572484/1837131

leetCode 217. Contains Duplicate 数组

原文:http://qiaopeng688.blog.51cto.com/3572484/1837131

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!