题目标签: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. 浏览器 chrome 360等 加载本地json 或者xml 文件

    添加启动参数 --allow-file-access-from-files 来自为知笔记(Wiz)

  2. Java 基础入门随笔(7) JavaSE版——面向对象定义、特征:封装、构造函数

    面向对象 面向过程:对于面向过程思想,强调的是过程(动作). 面向对象:对于面向对象思想,强调的是对象(实体). 特点: 1,面向对象就是一种常见的思想.符合人们的思考习惯.2,面向对象的出现,将复杂 ...

  3. HDU_2112_最短路

    题目链接:http://acm.hdu.edu.cn/status.php?user=l1526789512&pid=2112&status=5 HDU Today Time Limi ...

  4. C++标准库 vector排序

    前天要做一个对C++ STL的vector容器做一个排序操作,之前一直把vector当做一个容量可自动变化的数组,是的,数组,所以打算按照对数组进行排序的方法:用快速排序或是冒泡排序等算法自己写一个排 ...

  5. 网络编程 - join及守护线程

    一.Join实例(join理解为等待)import threading,timedef run(n): time.sleep(3) print ("task",n)start = ...

  6. org.hibernate.AnnotationException: mappedBy reference an unknown target entity property

    org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: xxxxxxx 原因是 ...

  7. Humidex POJ - 3299 (数学)

    题目大意 给定你三个变量中的两个输出剩下的那一个 题解 没有什么,就是把公式推出来即可,完全的数学题 代码 #include <iostream> #include <cmath&g ...

  8. [UVA11825]Hackers' Crackdown(状压dp)

    题解降智警告 吐槽降智警告 思路降智警告 代码降智警告 题目传送门 洛谷 果然水题做多了连半道难点的都能给咱干蒙... 水题做多了降智  --鲁迅 题目大意:见传送门 心路历程见末尾 正解(大概): ...

  9. Linux之sed:删除某行以及替换

    sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行为单位进行处理,可以将数据行进行替换.删除.新增.选取等特定工作,下面先了解一下sed的用法sed命令行格式为:         sed ...

  10. ubuntu jdk和tomcat配置

    先查看linux的版通过file /sbin/init命令,下载对应版本的jdk. 我的ubuntu是64位的(桌面系统),所以下载的是jdk-7u71-linux-x64.tar.gz 在home的 ...