Leetcode 217. Contains Duplicate Array

Source: Internet
Author: User

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 ele ment is distinct.

Main topic:

Any character found in the array with a number of occurrences greater than or equal to 2 times returns True, and False if every character in the array occurs 1 times.

The code is as follows:

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

This article is from the "Do Your best" blog, so be sure to keep this source http://qiaopeng688.blog.51cto.com/3572484/1837131

Leetcode 217. Contains Duplicate Array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.