(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 ...
随机推荐
- html之ol标签
有序列表,请使用 CSS 来定义列表的类型. 通常和li配对使用 HTML5新属性: compact reversed:降序 start:有序列表的起始值 type:在列表中使用标记类型(1,A,a, ...
- Jenkins入门系列之
Jenkins入门系列之——00答疑解惑 Jenkins进阶系列之——11修改Jenkins用户的密码 Jenkins进阶系列之——12详解Jenkins节点配置 Jenkins进阶系列之——13修改 ...
- comet4j文档
Comet4J配置参数表 <!--Comet4J配置 --> <listener> <description>Comet4J容器侦听</description ...
- astats日志分析系统
Awstats是一个免费非常简洁而且强大有个性的网站日志分析工具. 功能: 一:访问量,访问次数,页面浏览量,点击数,数据流量等 二:精确到每月.每日.每小时的数据 三:访问者国家 四:访问者IP 五 ...
- MVC4 WebAPI(二)——Web API工作方式
http://www.cnblogs.com/wk1234/archive/2012/05/07/2486872.html 在上篇文章中和大家一起学习了建立基本的WebAPI应用,立刻就有人想到了一些 ...
- 利用Boost影响Lucene查询结果的排序
转自:http://catastiger.iteye.com/blog/803796 前提:不对结果做sort操作. 在搜索中,并不是所有的Document和Fields都是平等的.有些技术会要 ...
- 【SVN】win7 搭建SVN服务器
介绍 SVN分为客户端和服务端: 服务端: 常用的主要有2个,分别为: 1. VisualSvn Server:免费,集成了Subsersion和Apache,安装使用非常简单: 2. SubVers ...
- iframe获取父、子窗口的方法
jquery.js调用iframe父窗口与子窗口元素的方法 1. jquery在iframe子页面获取父页面元素代码如下: $("#objid",parent.document) ...
- 127 Word Ladder
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest t ...
- ahk鼠标连击工具
;x = 0开始点击,x = 1暂停点击 ^::ck_start() ^::ck_end() ck_start() { x = { Click } } ck_end() { x = else x = ...