LeetCode(217)Contains Duplicate

时间:2020-12-13 09:29:27

题目

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. Java多线程简析

    一.线程的状态: 线程共有下面4种状态: 1.新建状态(New): 新创建了一个线程对象,当你用new创建一个线程时,该线程尚未运行. 2.就绪状态(Runnable): 线程对象创建后,其他线程调用 ...

  2. oracle for loop循环以及游标循环

    1. for in loop形式 DECLARE    CURSOR c_sal IS SELECT employee_id, first_name || last_name ename, salar ...

  3. 【COM学习】之一、QueryInterface

    开始先说一句,学习com之前要学好c++ 对象模型. QueryInterface的使用: QueryInterface是IUnknown的一个成员函数,客户可以通过此函数来查询某个组件是否支持某个特 ...

  4. Junit 入门使用教程

    1.Junit 是什么? JUnit是一个Java语言的单元测试框架.它由Kent Beck和Erich Gamma建立,逐渐成为源于Kent Beck的sUnit的xUnit家族中最为成功的一个JU ...

  5. maven下载源码

    能下载到源代码的原则是仓库中打了resource的jar包 1.使用命令 mvn dependency:sources 下载依赖包的源代码. mvn dependency:sources -Ddown ...

  6. VS2013配置OPENCV2&period;4&period;9

    转载自->这里 设置opencv SDK解压目录,点击Extract后解压 我是习惯于解压到这个位置的. 解压过程如上图. 2.         文件目录介绍 解压后会在目录下生成opencv的 ...

  7. pip安装pycrypto报错:Microsoft Visual C&plus;&plus; 14&period;0 is required&period; 和 SSLError&colon; HTTPSConnectionPool的解决办法

    今天本打算把[Python3爬虫]网易云音乐爬虫 的代码敲一遍, 但是在安装pycrypto老是报错, 由于我计算是win10, 并且也有vs2017 python3环境下安装pycrypto的一些问 ...

  8. yarn不是内部指令 react-native不是内部指令

    1.先查看是否全局安装 2.我遇到的是,全局安装了,依然有问题. 昨天装了一个高版本的node,成功后有个黑窗口我点了几个回车,在我的环境变量里加了一大推重复的变量,删除就正常了,如下图是我删完之后的

  9. 即将上线的Hive服务器面临的一系列填坑笔记

    即将上线的Spark服务器面临的一系列填坑笔记 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.18/10/19 16:36:31 WARN metastore.ObjectSt ...

  10. Java Jersey2使用总结

    原文  http://blog.segmentfault.com/lenbo_ma/1190000000495321 主题 Java 前言 在短信平台一期工作中,为便于移动平台的开发,使用了Java ...