(easy)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.
代码如下:
public class Solution {
public boolean containsDuplicate(int[] nums) {
Set<Integer> set=new HashSet<Integer>();
int len=nums.length;
for(int i=0;i<len;i++){
set.add(nums[i]);
}
if(len>set.size())
return true;
else
return false;
}
}
运行结果:
(easy)LeetCode 217.Contains Duplicate的更多相关文章
- 25. leetcode 217. Contains Duplicate
217. Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your ...
- leetcode 217. Contains Duplicate 287. Find the Duplicate Number 442. Find All Duplicates in an Array 448. Find All Numbers Disappeared in an Array
后面3个题都是限制在1-n的,所有可以不先排序,可以利用巧方法做.最后两个题几乎一模一样. 217. Contains Duplicate class Solution { public: bool ...
- LN : leetcode 217 Contains Duplicate
lc 217 Contains Duplicate 217 Contains Duplicate Given an array of integers, find if the array conta ...
- [LeetCode] 217. Contains Duplicate 包含重复元素
Given an array of integers, find if the array contains any duplicates. Your function should return t ...
- LeetCode 217. Contains Duplicate (包含重复项)
Given an array of integers, find if the array contains any duplicates. Your function should return t ...
- leetcode 217 Contains Duplicate 数组中是否有重复的数字
Contains Duplicate Total Accepted: 26477 Total Submissions: 73478 My Submissions Given an array o ...
- leetcode 217 Contains Duplicate 数组中是否有反复的数字
Contains Duplicate Total Accepted: 26477 Total Submissions: 73478 My Submissions Given an array o ...
- Java for LeetCode 217 Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return t ...
- LeetCode 217 Contains Duplicate
Problem: Given an array of integers, find if the array contains any duplicates. Your function should ...
随机推荐
- discuz 发布分类信息,能不能设置单版块去掉“发帖子”(默认点发帖后为自定义的默认分类信息模版)
http://www.discuz.net/forum.php?mod=viewthread&tid=3365198&page=1#pid26849156
- Oracle “CONNECT BY” 使用 [转]
Oracle “CONNECT BY”是层次查询子句,一般用于树状或者层次结果集的查询.其语法是: 1 [ START WITH condition ]2 CONNECT BY [ NOCYCLE ] ...
- 客户端TortoiseSVN的安装及使用方法
一.客户端TortoiseSVN的安装 运行TortoiseSVN程序,点击Next,下面的截图顺序即为安装步骤: 图1: 图2: 图3: 图4: 点击Finish按钮后会提示重启系统,其实不重启也没 ...
- Hub, bridge, switch, router, gateway的区别
这些概念性的东西,其实,有的区别不是很大,有的区别很大. Hub 就是一个重复转发器,就是从一个port接受到数据后,就会原样的向其他的所有端口发送刚才收到的数据.个人理解为是工作在物理层的东西.但是 ...
- 如何将NetBeans转换为英文版(图)
很郁闷,又是一个系统语言的问题. NetBeans下载下来之后,怎么装都是个中文版,或者半中文半英文,不伦不类的.上网找了一个圈,很多都讲得不清楚,最后终于有了一个答案: 在NetBeans的配置文件 ...
- mongodb基本语句使用
mongodb学习:##mongodb基础##数据库常用命令##用户相关##修改.添加.删除集合数据##条件操作符##创建表 ------------------------------------- ...
- java运用Comparator为对象排序
要排序的类需要实现Comparator接口,重写compare方法: user类及实现接口的内部类: package test; import java.util.Comparator; public ...
- SDS查看部署在集成TOMCAT服务器中的项目目录结构
- HTTP协议下保证登录密码不被获取更健壮方式
说到在http协议下用户登录如何保证密码安全这个问题: 小白可能第一想法就是,用户在登录页面输入密码进行登录时,前台页面对用户输入的密码进行加密,然后把加密后的密码作为http请求参数通过网络发 ...
- U3d中实现A*寻路,附源文件
图片看不清楚,请点击看大图 http://pan.baidu.com/s/1pKwmOYn 写了好多,没保存,哎哎哎 空格键开始移动