博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
217. Contains Duplicate
阅读量:7102 次
发布时间:2019-06-28

本文共 909 字,大约阅读时间需要 3 分钟。

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.
Example 1:

Input: [1,2,3,1]Output: true

Example 2:

Input: [1,2,3,4]Output: false

Example 3:

Input: [1,1,1,3,3,4,3,2,4,2]Output: true

难度:easy

题目:给定整数数组,找出其中是否含有重复元素。方法应该返回true如果发现某元素至少出现两次,否则返回false.

思路:hashset

Runtime: 10 ms, faster than 64.18% of Java online submissions for Contains Duplicate.

Memory Usage: 40.9 MB, less than 81.42% of Java online submissions for Contains Duplicate.

class Solution {    public boolean containsDuplicate(int[] nums) {        Set
set = new HashSet<>(); for (int i = 0; i < nums.length; i++) { if (set.contains(nums[i])) { return true; } set.add(nums[i]); } return false; }}

转载地址:http://jzuhl.baihongyu.com/

你可能感兴趣的文章
Nginx配置文件nginx.conf中文注释
查看>>
20120520 linux下mysql的卸载
查看>>
BIND和DNS名称解析
查看>>
hadoop基本操作命令
查看>>
大型web项目解决方案
查看>>
根据模型大小,限定摄像头旋转角度(上,下,左,右)
查看>>
图文详解 正向代理,反向代理,透明代理
查看>>
haproxy之二
查看>>
tomcat在linux安装
查看>>
我的友情链接
查看>>
19个PHP模板引擎
查看>>
iphone的PC端管理软件开源项目
查看>>
ORA-65085: cannot open pluggable database in read-only mode问题解决
查看>>
mysql导入报错Variable 'sql_notes' can't be set to the value of 'NULL'
查看>>
升级Xcode8之后 XMPP 遇到重定义的问题 Redefinition of module 'dnssd'
查看>>
RHEL6.4 KVM虚拟化网卡桥接,PXE无人值守安装虚拟机
查看>>
我的友情链接
查看>>
PDF转换为SWF
查看>>
Maven项目下update maven后Eclipse报错:java.lang.ClassNotF
查看>>
linux开机启动流程
查看>>