[leetcode] Contains Duplicate
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.
class Solution
{
public:
bool containsDuplicate(vector<int> &nums)
{
set<int> S;
for(int i=; i<nums.size(); i++)
{
if(S.find(nums[i]) == S.end())
S.insert(nums[i]);
else
return true;
}
return false;
}
};
class Solution
{
public:
bool containsDuplicate(vector<int> &nums)
{
sort(nums.begin(), nums.end());
for(int i=; i<nums.size(); i++)
if(nums[i-] == nums[i])
return true; return false;
}
};
[leetcode] Contains Duplicate的更多相关文章
- [LeetCode] Remove Duplicate Letters 移除重复字母
		
Given a string which contains only lowercase letters, remove duplicate letters so that every letter ...
 - [LeetCode] 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 II 包含重复值之二
		
Given an array of integers and an integer k, return true if and only if there are two distinct indic ...
 - [LeetCode] Contains Duplicate 包含重复值
		
Given an array of integers, find if the array contains any duplicates. Your function should return t ...
 - [LeetCode] Delete Duplicate Emails 删除重复邮箱
		
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...
 - LeetCode Remove Duplicate Letters
		
原题链接在这里:https://leetcode.com/problems/remove-duplicate-letters/ 题目: Given a string which contains on ...
 - [LeetCode] Find Duplicate Subtrees 寻找重复树
		
Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only ne ...
 - [LeetCode] Find Duplicate File in System 在系统中寻找重复文件
		
Given a list of directory info including directory path, and all the files with contents in this dir ...
 - LeetCode Find Duplicate File in System
		
原题链接在这里:https://leetcode.com/problems/find-duplicate-file-in-system/description/ 题目: Given a list of ...
 - [Leetcode] Contains Duplicate III
		
Given an array of integers, find out whether there are two distinct indices i and j in the array suc ...
 
随机推荐
- RGB和HSB的转换推算
			
RGB三原色是基于人肉眼对光线的生理作用.人眼内有三种椎状体“对这三种光线频率所能感受的带宽最大,也能独立刺激这三种颜色的受光体”,因此RGB称为三原色.比如,黄色波长的光对人眼的刺激效果,和红色与绿 ...
 - 用户无法进入SDSF,报NO GROUP ASSIGNMENT错误
			
注:命令行小写部分表出需要根据自己的情况改变!! a)激活SDSF资源类 SETROPTS CLASSACT(SDSF) b)查看SDSF资源类的PROFILE RLIST SDSF * c)如果不存 ...
 - java模仿qq好友面板的布局(BoxLayout问题)
			
.............. JLabel ll = new JLabel(dlg.getNameText() + ":" + dlg.getIPText(), ii[index] ...
 - maven -- 问题解决(一)解决eclipse中maven项目出现的问题
			
配置项目时出现的错误: error: Cannot change version of project facet Dynamic Web Module to 2.5. error: One or m ...
 - Web开发入门疑问收集(不定期更新)
			
bootstrap container和container-fluid的区别 原始链接 container 根据显示设备满足的最小宽度,来决定实际内容宽度,是一个根据设置内容阶梯式响应的布局. 例子: ...
 - 【分布式】RPC初探
			
事先声明:本文代码参考自Dubbo作者的博客. RPC(Remote Procedure Call)远程过程调用,是分布式系统当中必不可少的一个玩意.比如说在单机系统当中,我想调用某个方法,直接调就可 ...
 - Javascript起源...
			
Javascript的设计思路是这样的: (1)借鉴C语言的基本语法: (2)借鉴Java语言的数据类型和内存管理: (3)借鉴Scheme语言,将函数提升到"第一等公民"(fir ...
 - SQL Server技术问题之视图优缺点
			
优点: 一.简单性.视图不仅可以简化用户对数据的理解,也可以简化他们的操作.那些被经常使用的查询可以被定义为视图,从而使用户不必为以后的操作每次都指定全部的条件. 二.安全性.通过视图用户只能查询和修 ...
 - 数论 --- 费马小定理 + 快速幂 HDU 4704 Sum
			
Sum Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=4704 Mean: 给定一个大整数N,求1到N中每个数的因式分解个数的 ...
 - 正则表达式相关:C# 抓取网页类(获取网页中所有信息)
			
类的代码: using System; using System.Data; using System.Configuration; using System.Net; using System.IO ...