题目

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. RL_RTX函数

    1 延时:os_itv_set(usFrequency) //设置延时周期,配合os_itv_wait使用:os_itv_wait() 是绝对延迟是包含调用前的时间, os_dly_wait() 是相 ...

  2. Android sdk manager 显示 “Done loading packages”,该怎么办?

    试了这个方法:请用管理员的身份运行"SDK Manager.exe".不管用. 下面的方法可以: 在SDK Manager下Tools->Options打开了SDK Mana ...

  3. C#实现程序单例日志输出

    对于一个完整的程序系统,一个日志记录是必不可少的.可以用它来记录程序在运行过程中的运行状态和报错信息.比如,那些不想通过弹框提示的错误,程序执行过程中捕获的异常等. 首先,在你的解决方案中,适当的目录 ...

  4. winform代码生成器(三)

    代码下载 地址 http://pan.baidu.com/s/1nuZjyat 接上面的两篇. 用户有时对 从表的 排版不喜欢,可以因某些字太长,需要拉长一些,有些则需要隐藏. 有什么办法呢? 我的思 ...

  5. 利用mysqldump备份magento数据库

    在Magento开发和维护过程中,经常需要将Magento的数据库导出.导入,这些工作可以通过mysqldump这个工具来实现. 下面我来简单介绍一下mysqldump在导出导入Magento dat ...

  6. js根据鼠标方向划入遮罩层

    js根据鼠标方向划入遮罩层: <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...

  7. WebClient UI和Tomcat的启动器

    WebClient UI 我们在WebClient UI的开发工具里点了Test按钮, 会在浏览器以测试模式打开选中的view.这背后发生了什么事?注意浏览器地址栏的bspwd_cmp_test,这是 ...

  8. poj 3159 Candies (差分约束)

    一个叫差分约束系统的东西.如果每个点定义一个顶标x(v),x(t)-x(s)将对应着s-t的最短路径. 比如说w+a≤b,那么可以画一条a到b的有向边,权值为w,同样地给出b+w2≤c,a+w3≤c. ...

  9. JS实现全排列

    https://www.jb51.net/article/39291.htm JavaScript全排列的六种算法 具体实现 算法一:交换(递归) 复制代码代码如下: <html xmlns=& ...

  10. FastText算法

    转载自: https://www.cnblogs.com/huangyc/p/9768872.html 0. 目录 1. 前言 2. FastText原理 2.1 模型架构 2.2 层次SoftMax ...