(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 ...
随机推荐
- eclipse中复制项目更名注意事项
一.更改项目名称 web project Settings; 二.pom.xml中的项目名称更改
- 目录处理工具类 DealWithDir.java
package com.util; import java.io.File; /** * 目录处理工具类 * */ public class DealWithDir { /** * 新建目录 */ p ...
- visibility和display的区别
大多数人很容易将CSS属性display和visibility混淆,它们看似没有什么不同,其实它们的差别却是很大的. visibility属性用来确定元素是显示还是隐藏的,这用visibility=& ...
- c# .net sha256 16进制 64位 签名
public static string GetSHA256hash(string input, string _input_charset) { byte[] clearBytes = Encodi ...
- 【转】如何使用PhoneGap打包Web App
如何使用PhoneGap打包Web App 最近做了一款小游戏,定位是移动端访问,思来想去最后选择了jQuery mobile最为框架,制作差不多以后,是否可以打包成App,恰好以前对PhoneGap ...
- 剑指offer系列52---约瑟夫环问题
[题目]0,1,...n排成一个圈,从0开始每次删除第m个数,求圆圈最后个数. * [思路]1 用数组模拟圆圈.当数到最后一个数即index==n时,令index==0 重头开始遍历: * 当遇到已经 ...
- Linux 2.6 内核实时性分析 (完善中...)
经过一个月的学习,目前对linux 下驱动程序的编写有了入门的认识,现在需要着手实践,编写相关的驱动程序. 因为飞控系统对实时性有一定的要求,所以先打算学习linux 2.6 内核的实时性与任务调 ...
- C# new 和 override.
http://www.dotblogs.com.tw/skychang/archive/2012/05/10/72114.aspx?fid=60865
- Tomcat远程调试catalina.sh的配置
#!/bin/sh # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license ...
- Linux客户端、服务器、窗口管理器的关系
嵌入式linux中文站发现很多LINUX初学者在学习linux图形方面的知识时会遇到一些概念,如:X.X11.Xfree86.WM.KDE.GNOME.QT.QT/E.Qtopia.DirectFB. ...