217. Contains Duplicate

Problem

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.

Example

Input: [1,2,3,1]
Output: true
Input: [1,2,3,4]
Output: false
Input: [1,1,1,3,3,4,3,2,4,2]
Output: true

Code

static int var = [](){
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    return 0;
}();
class Solution {
public:
    bool containsDuplicate(vector& nums) {
        map dict;
        for(int i=0;i

Result

217. Contains Duplicate.png

你可能感兴趣的:(217. Contains Duplicate)