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. Swift使用Alamofire实现网络请求

    Alamofire是一个用Swift编写的HTTP网络库,由此前热门开源项目AFNetworking的的作者mattt开发,可非常简单地用于异步网络通信. 要获取最新版本的 Alamofire,前往h ...

  2. System.AccessViolationException,尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

    从事件查看器中发现,IIS不定期崩溃并重启的现象.抓取crash dump文件后,发现能够看到异常,但没有堆栈信息(主要是只会看托管代码的堆栈,非托管的不清楚.),问题表现及dump日志的截图如下: ...

  3. sql常用语句--转载

    一.基础 .说明:创建数据库 CREATE DATABASE database-name .说明:删除数据库 drop database dbname .说明:备份sql server --- 创建 ...

  4. SQL Server 2008维护计划 出错 无法实现自动备份

    ,MaintenancePlan.Subplan_1,错误,0,HBZGQ\TESTSQLSERVER,MaintenancePlan.Subplan_1,(作业结果),,该作业失败. 用户 sa 调 ...

  5. fastjson 使用方法

    Fastjson介绍 Fastjson是一个Java语言编写的JSON处理器. 1.遵循http://json.org标准,为其官方网站收录的参考实现之一. 2.功能qiang打,支持JDK的各种类型 ...

  6. MyBatis java and MySql local variables

    <insert id="create" parameterType="models.entities.CategoryEntity"> set @c ...

  7. 在阿里云 centos 6.3上面安装php5.2(转)

    由于php程序使用了Zend Optimizer,只能使用php5.2, yum 上的php 是5.3的版本,只能重新安装php:安装步骤如下: 先卸载 php5.3的相关东西: yum remove ...

  8. 程序员书单_java web编程篇

    李兴华JavaWeb开发实战经典 http://download.csdn.net/detail/shenzhq1980/9137653 Servlet与JSP核心编程 第2版_1 http://do ...

  9. 【设计模式】装饰者模式(Decorator)

    装饰者模式 动态的将责任附加到对象上,若要扩展功能,装饰者提供了比继承更有弹性的替代方案. Java I/O中的装饰类 示例:coffee装饰者模式类图 顶层超类 被装饰组件-被装饰者 装饰者抽象类 ...

  10. 【转】String.format详解

    一.前言 String.format 作为文本处理工具,为我们提供强大而丰富的字符串格式化功能,为了不止步于简单调用 String.format("Hello %s", " ...