题目

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.

分析

判断所给整数序列中有无重复元素。

AC代码

class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
if (nums.empty())
return false; unordered_set<int> us;
int len = nums.size(); for (int i = 0; i < len; ++i)
{
if (us.count(nums[i]) != 0)
return true;
else
us.insert(nums[i]);
}
return false; }
};

LeetCode(217)Contains Duplicate的更多相关文章

  1. LeetCode(220) Contains Duplicate III

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

  2. LeetCode(219) Contains Duplicate II

    题目 Given an array of integers and an integer k, find out whether there are two distinct indices i an ...

  3. LeetCode(275)H-Index II

    题目 Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimi ...

  4. LeetCode(154) Find Minimum in Rotated Sorted Array II

    题目 Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates are allowed? W ...

  5. LeetCode(122) Best Time to Buy and Sell Stock II

    题目 Say you have an array for which the ith element is the price of a given stock on day i. Design an ...

  6. LeetCode(116) Populating Next Right Pointers in Each Node

    题目 Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode * ...

  7. LeetCode(113) Path Sum II

    题目 Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given ...

  8. LeetCode(107) Binary Tree Level Order Traversal II

    题目 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from l ...

  9. LeetCode(4)Median of Two Sorted Arrays

    题目 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...

随机推荐

  1. 渣渣菜鸡的 ElasticSearch 源码解析 —— 启动流程(上)

    关注我 转载请务必注明原创地址为:http://www.54tianzhisheng.cn/2018/08/11/es-code02/ 前提 上篇文章写了 ElasticSearch 源码解析 -- ...

  2. windows黑窗口关于java程序的常用命令

    1.启动java程序 我要运行:E:\code\nhtask下的ElectricEye-0.0.1-SNAPSHOT.jar程序 #切换到程序目录cd E:\code\nhtaskE: java -j ...

  3. java jmap

    jmap : 命令用于生成堆转储快照.它还可以查询finalize执行队列.Java堆和永久代的详细信息,如空间使用率.当前用的是哪种收集器等. 命令格式: jmap [option] vmid op ...

  4. Vue2.0 官方文档学习笔记

    VUE2.0官方文档 基础部分: 1.VUE简介 Vue是一个基于MVVM的框架,其中M代表数据处理层,V代表视图层即我们在Vue组件中的html部分,VM即M和V的结合层,处理M层相应的逻辑数据,在 ...

  5. Android开发学习——小细节注意

    Android中通过Intent调用其他应用的方法(转) Android中两种序列化方式的比较Serializable和Parcelable http://www.jcodecraeer.com/a/ ...

  6. 编写SQL语句操作数据库(慕课SQLite笔记)

    安卓常用数据存储方式之一SQLite学习及操作笔记 0.视频地址:http://www.imooc.com/video/3382 1.每个程序都有自己的数据库 默认情况下是各自互不干扰 1)创建一个数 ...

  7. 假如m是奇数,且m>=3,证明m(m² -1)能被8整除

    m是奇数,且m>=3 =>m可以用表达式2n-1,n>=2 =>m²-1 = (2n-1)²-1 =>m²-1 = 4n²-4n+1-1 =>m²-1 = 4n²- ...

  8. [windows]窗口文件夹中使用常见任务

    文件夹中使用常见任务,如截图所示增加红色框部分. 设置步骤: 我的电脑--〉右键--〉属性--〉高级选项--〉性能设置--〉自定义:勾选在文件夹中使用常见任务.

  9. 【Python图像特征的音乐序列生成】关于数据集的分享和样例数据

    数据集还在制作中,样例数据如下: 我将一条数据作为一行,X是ID,O代表了情感向量,S是速度,是一个很关键的参数,K是调式,M是节拍,L是基本拍.后面是ABC格式的序列,通过embedding化这些音 ...

  10. 在Linux系统里安装Virtual Box的详细步骤

    今天我试图在Linux 服务器上安装Kyma时,遇到如下错误消息: E1009 23:51:37.685891 358 start.go:174] Error starting host: Error ...