【leetcode】Contains Duplicate

原创 2015年11月19日 21:39:03

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了……

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

leetcode--Contains Duplicate

Given an array of integers, find if the array contains any duplicates. Your function should return t...

[LeetCode]217-Contains Duplicate 几种解法

数组重复元素查找: 解法一 :sort 后相邻位比较  40ms class Solution { public: bool containsDuplicate(vector& nums)...

【leetcode题解】【再看一遍】【86】【M】Contains Duplicate III

Given an array of integers, find out whether there are two distinct indices i and j in the array suc...

《leetCode》:Contains Duplicate III

题目Given an array of integers, find out whether there are two distinct indices i and j in the array s...

LeetCode------Contains Duplicate

题目简介 Given an array of integers, find if the array contains any duplicates. Your function should r...

LeetCode-217. Contains Duplicate (Java)

Given an array of integers, find if the array contains any duplicates. Your function should return t...
  • NOadu
  • NOadu
  • 2017-06-27 11:17
  • 105

leetcode_[python/C++逐步深入]_217. Contains Duplicate(深度分析位操作算法)

题目链接 【题目】 Given an array of integers, find if the array contains any duplicates. Your function sho...

leetcode之Contains Duplicate II 问题

问题描述: Given an array of integers and an integer k, find out whether there are two distinct indicesi...

leetcode 217. Contains Duplicate

leetcode 217. Contains Duplicate题目 Given an array of integers, find if the array contains any dupl...

leetcode: (219) Contains Duplicate II

【Question】 Given an array of integers and an integer k, find out whether there are two distinct ind...
  • zk031
  • zk031
  • 2015-08-28 20:50
  • 158
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)