题目标签:HashMap

  题目给了我们一个size 为 2N 的int array,其中有 N + 1 个唯一的 数字,让我们找出那个重复的数字。

  利用hashset,把每一个数字存入,一旦发现有重复的,就返回这个数字。

Java Solution:

Runtime: 4 ms, faster than 93.76%

Memory Usage: 40.7 MB, less than 65.88%

完成日期:03/11/2019

关键点:hashset

class Solution
{
public int repeatedNTimes(int[] A)
{
Set<Integer> set = new HashSet<>();
int result = -1; for(int i=0; i < A.length; i++)
{
if(set.contains(A[i]))
{
result = A[i];
break;
}
else
set.add(A[i]);
} return result;
}
}

参考资料:N/A

LeetCode 题目列表 - LeetCode Questions List

题目来源:https://leetcode.com/

LeetCode 961. N-Repeated Element in Size 2N Array (重复 N 次的元素)的更多相关文章

  1. Leetcode961. N-Repeated Element in Size 2N Array重复N次的元素

    在大小为 2N 的数组 A 中有 N+1 个不同的元素,其中有一个元素重复了 N 次. 返回重复了 N 次的那个元素. 示例 1: 输入:[1,2,3,3] 输出:3 示例 2: 输入:[2,1,2, ...

  2. 116th LeetCode Weekly Contest N-Repeated Element in Size 2N Array

    In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeate ...

  3. 【Leetcode_easy】961. N-Repeated Element in Size 2N Array

    problem 961. N-Repeated Element in Size 2N Array solution: class Solution { public: int repeatedNTim ...

  4. LeetCode--Sort Array By Parity && N-Repeated Element in Size 2N Array (Easy)

    905. Sort Array By Parity (Easy)# Given an array A of non-negative integers, return an array consist ...

  5. 【LeetCode】961. N-Repeated Element in Size 2N Array 解题报告(Python & C+++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcod ...

  6. LeetCode 961. N-Repeated Element in Size 2N Array

    In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeate ...

  7. LeetCode 961 N-Repeated Element in Size 2N Array 解题报告

    题目要求 In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is re ...

  8. 【leetcode】961. N-Repeated Element in Size 2N Array

    题目如下: In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is r ...

  9. LC 961. N-Repeated Element in Size 2N Array【签到题】

    In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeate ...

随机推荐

  1. CentOS7上安装稻壳CMS

    CentOS7上安装稻壳CMS 1, 安装用途 为了给某公司建设一个小型网站,租用了一个阿里云ECS服务器,最基础的硬件配置,因此选择了CentOS7操作系统. 稻壳CMS(docCMS)源于深喉咙C ...

  2. 获取WebBrowser全cookie 和 httpWebRequest 异步获取页面数据

    获取WebBrowser全cookie [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true) ...

  3. MySql(四)Select条件查询

    select条件查询的格式如下: SELECT 查询列表FROM 表名WHERE 筛选条件:123456根据筛选条件可以分为以下几类: 按照条件按表达式进行筛选 常用条件运算符如下:> .< ...

  4. Sturts2几个常用内建拦截器的介绍

    Sturts2几个常用内建拦截器的介绍:1)conversation:这是一个处理类型转换错误的拦截器,它负责将类型转换错误从ActionContext中取出,并转换成Action的FieldErro ...

  5. 60s倒计时

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. js的title提示

    $(function() { //先在页面创建一个层 var jqtip = $("<div id='jqtip20130719'" + "style='paddi ...

  7. git 忽略文件[.gitignore]常用配置

    .idea .buildpath .project .settings .Ds_Store composer.json composer.lock a.php /public/uploads /run ...

  8. Python 开发面试题

    Python部分 将一个字符串逆序,不能使用反转函数 求从10到100中能被3或5整除的数的和 What is Python? What are the benefits of using Pytho ...

  9. [bzoj3209][花神的数论题] (数位dp+费马小定理)

    Description 背景众所周知,花神多年来凭借无边的神力狂虐各大 OJ.OI.CF.TC …… 当然也包括 CH 啦.描述话说花神这天又来讲课了.课后照例有超级难的神题啦…… 我等蒟蒻又遭殃了. ...

  10. C语言基础--数据

    c语言中数据: 在8位单片机种最常用的数据类型就是: unsigned char: 无符号字符型,位宽1个字节,8个位,表示的范围0~255(2^8-1) 在32位单片机中最常用的数据类型就是: un ...