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.

解题思路:

HashMap,JAVA实现如下:

    public boolean containsDuplicate(int[] nums) {
HashMap<Integer,Boolean> hm=new HashMap<Integer,Boolean>();
for(int num:nums){
if(hm.containsKey(num))
return true;
hm.put(num, true);
}
return false;
}

Java for LeetCode 217 Contains Duplicate的更多相关文章

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

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

  2. 25. leetcode 217. Contains Duplicate

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

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

  4. LN : leetcode 217 Contains Duplicate

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

  5. Java [Leetcode 217]Contains Duplicate

    题目描述: Given an array of integers, find if the array contains any duplicates. Your function should re ...

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

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

  7. Java for LeetCode 220 Contains Duplicate III

    Given an array of integers, find out whether there are two distinct indices i and j in the array suc ...

  8. Java for LeetCode 219 Contains Duplicate II

    Given an array of integers and an integer k, find out whether there there are two distinct indices i ...

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

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

随机推荐

  1. vim插件ctags的安装和使用

    vim插件ctags的安装和使用 2013-11-19 20:47 17064人阅读 评论(0) 收藏 举报  分类: 开发工具(3)  linux编程(9)  c/c++编程(11)  版权声明:本 ...

  2. Java字节流:FilterInputStream FilterOutputStream

    ----------------------------------------------------------------------------------- FilterInputStrea ...

  3. EDW on Hadoop(Hadoop上的数据仓库)技术选型和实践思考

    在这篇文章中, 将讨论EDW on Hadoop 有哪些备选方案, 以及我个人的倾向性, 最后是建构方法.  欢迎转载, 但必须注明原贴(刘忠武,  http://www.cnblogs.com/ha ...

  4. Ionic 常见问题及解决方案

    前言 Ionic是目前较为流行的Hybird App解决方案,在Ionic开发过程中会遇到很多常见的开发问题,本文尝试对这些问题给出解决方案. 一些常识与技巧 list 有延迟,可以在ion-cont ...

  5. git/gitLab

    gitlab安装:http://www.360doc.com/content/15/0603/14/21631240_475362133.shtml http://www.cnblogs.com/wi ...

  6. cas

    cas配置ladp地址:

  7. mysql 删除重复数据,并保存最新一条数据

    删除重复行 DELETE FROM ecm_member_login_session WHERE (number , client_code) IN ( ) AND update_time NOT I ...

  8. 大数据之Ganglia安装1

    0.前期准备修改主机名.ip.iptables关闭:时间同步:ntpdate -s time.windows.com;软件准备ganglia-3.7.1.tar.gz.ganglia-web-3.7. ...

  9. sass兼容IE8透明度方法

    你可以轻松的利用 {Sass::Script::Functions#ie_hex_str ie_hex_str} 函数对其做转换.$translucent-red: rgba(, , , 0.5); ...

  10. android 弹出的软键盘遮挡住EditText文本框的解决方案

    1.android 弹出的软键盘遮挡住EditText文本框的解决方案: 把Activit对应的布局文件filename.xml文件里的控件用比重设置布局.(例如:android:layout_wei ...