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的更多相关文章

  1. 25. leetcode 217. Contains Duplicate

    217. Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your ...

  2. 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 ...

  3. LN : leetcode 217 Contains Duplicate

    lc 217 Contains Duplicate 217 Contains Duplicate Given an array of integers, find if the array conta ...

  4. [LeetCode] 217. Contains Duplicate 包含重复元素

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  5. LeetCode 217. Contains Duplicate (包含重复项)

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  6. leetcode 217 Contains Duplicate 数组中是否有重复的数字

     Contains Duplicate Total Accepted: 26477 Total Submissions: 73478 My Submissions Given an array o ...

  7. leetcode 217 Contains Duplicate 数组中是否有反复的数字

     Contains Duplicate Total Accepted: 26477 Total Submissions: 73478 My Submissions Given an array o ...

  8. Java for LeetCode 217 Contains Duplicate

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  9. LeetCode 217 Contains Duplicate

    Problem: Given an array of integers, find if the array contains any duplicates. Your function should ...

随机推荐

  1. 使用面向对象思想处理cookie

    实例:使用面向对象思想处理cookie如果读者对cookie 不熟悉,可以在第七章学习它的使用方法,虽然在那里创建了几个通用函数用于cookie 的处理,但这些函数彼此分离,没有体现出是一个整体.联想 ...

  2. 解决Android AVD的方向键DPAD不能用的问题

    Android AVD在生成出来一个新的模拟器之后默认都是不能够使用DPAD的.原因是它禁用了. 解决方式如下 : 找到C:\Documents and Settings\Administrator\ ...

  3. Saiku操作界面的简化

    在安装完毕Saiku后,由于是社区版本,所以界面上存在很多升级为商业版的文字.为了使得系统不那么碍眼,可通过如下方式更改来去除相应的内容: 1.去除查询页面的升级为商业版的提示 You are usi ...

  4. linux设置系统日期时间

    设置当前日期: date -s 08/06/2015 设置当前时间:date -s 10:03:00 写入BIOS: clock -w 显示当前日期时间: date

  5. redis的启动与停止

    启动: redis-server /etc/redis/6379.conf 停止:进入src文件目录 redis-cli -a 数据库密码 shutdown

  6. 触发器 'SA.U_USER_INFO_TRG' 无效且未通过重新验证--Oracle序列

    程序开发时报错:触发器 'SA.U_USER_INFO_TRG' 无效且未通过重新验证打开触发器的定义,执行其中的语句,发现序列 U_USER_INFO_SEQ 未定义.什么是序列呢?序列相当于sql ...

  7. [nginx]Nginx禁止访问robots.txt防泄漏web目录

    关于robots.txt文件:搜索引擎通过一种程序robot(又称spider),自动访问互联网上的网页并获取网页信 息.您可以在您的网站中创建一个纯文本文件robots.txt,在这个文件中声明该网 ...

  8. 使用Cyclone IV控制DDR2

    根据你的DDR2手册配置好megacore,megacore会生成一个example top: 在quartus中运行megacore生成的xxx_pin_assignments.tcl,指定DDR2 ...

  9. php常见判断

    当要 判断一个变量是否已经声明的时候 可以使用 isset 函数 当要 判断一个变量是否已经赋予数据且不为空 可以用 empty 函数 当要 判断 一个变量 存在且不为空 先isset 函数 再用 e ...

  10. Winfrom DateGridView 实现Button列禁用

    Form窗体如下所示: 实现如下: using System; using System.Collections.Generic; using System.Drawing; using System ...