LeetCode(217)Contains Duplicate
题目
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的更多相关文章
- LeetCode(220) Contains Duplicate III
题目 Given an array of integers, find out whether there are two distinct indices i and j in the array ...
- LeetCode(219) Contains Duplicate II
题目 Given an array of integers and an integer k, find out whether there are two distinct indices i an ...
- LeetCode(275)H-Index II
题目 Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimi ...
- LeetCode(154) Find Minimum in Rotated Sorted Array II
题目 Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates are allowed? W ...
- 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 ...
- LeetCode(116) Populating Next Right Pointers in Each Node
题目 Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode * ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Django使用网站图标
默认情况下,浏览器访问一个网站的时候,同时还会向服务器请求“/favicon.ico”这个URL,目的是获取网站的图标. 若是没有配置的话,Django就会返回一个404错误,并且浏览器接收到这个40 ...
- linux下火狐浏览器安装flash player插件
1 去官方网站下载flash player 安装包.后缀名为.tar.gz,假设名称为flash.tar.gz 默认在桌面 2 下载后解压缩,使用以下命令 #tar -zxvf /root/Deskt ...
- pytorch 安装错误,报 GLIBCXX_3.4.20 错误
pytorch 从源码安装 链接:http://blog.csdn.net/u012442157/article/details/78134888 发现错误: 解决方案: http://blog.cs ...
- zuul的本地跳转
- ios获取数据之encodeURI 和 decodeURI
在APP开发过程中,免不了要进行ios的数据处理,在ios传递数据的过程中,会出现JSON数据获取不到的情况,这时候就轮到encodeURI 和 decodeURI出马了. 1.encodeURI,d ...
- Map-HashMap-LinkedHashMap-Map.Entry-Collections-可变参数
一.Map 接口(java.util) 定义:public interface Map<K,V> 介绍: (1)Map是一个接口,含有两个泛型,创建子类对象的时候,需要传递两个泛型 ...
- 数据结构-List接口-LinkedList类-Set接口-HashSet类-Collection总结
一.数据结构:4种--<需补充> 1.堆栈结构: 特点:LIFO(后进先出);栈的入口/出口都在顶端位置;压栈就是存元素/弹栈就是取元素; 代表类:Stack; 其 ...
- eclipse、idea安装lombok插件
今天新项目中,用到了lombok知识,很方便. 但是使用之前,需要在eclipse.idea中安装插件才可以使用,配置如下. 一:在开发工具中安装插件: Eclipse: 下载地址:https:// ...
- python中的uuid4
Help on function uuid4 in module uuid: uuid4() Generate a random UUID.
- IT部门域事件与业务分析
IT event--->system--->IT dept |--------------->IT dept |--------------->system 域事件分类: 直接 ...