LeetCode 961. N-Repeated Element in Size 2N Array (重复 N 次的元素)
题目标签: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 次的元素)的更多相关文章
- 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, ...
- 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 ...
- 【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 ...
- 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 ...
- 【LeetCode】961. N-Repeated Element in Size 2N Array 解题报告(Python & C+++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcod ...
- 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 ...
- 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 ...
- 【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 ...
- 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 ...
随机推荐
- FTP初始化文件.netrc使用技巧[转发]
FTP初始化文件.netrc使用技巧 FTP(文件传输)和E-mail(电子邮件).Telnet(远程登录)一样,是 Internet的三大主要功能之一.因为使用频繁,用户往往会遇到各种 各样的问题, ...
- Discuz!伪静态原理分析
伪静态在seo火热的时代,是每个站长都比较关注的问题,discuz!论坛如何伪静态,为什么伪静态失效了,为什么列表页无法实现伪静态,为什么有些页面不是伪静态呢?下面dz官方nxy105从两个角度入手为 ...
- RocketMQ学习笔记(16)----RocketMQ搭建双主双从(异步复制)集群
1. 修改RocketMQ默认启动端口 由于只有两台机器,部署双主双从需要四个节点,所以只能修改rocketmq的默认启动端口,从官网下载rocketmq的source文件,解压后使用idea打开,全 ...
- 13Oracle Database 存储过程
Oracle Database 存储过程 触发器相当于java中的事件监听,当某事件发生时激活特定的事件并执行相应的逻辑 DML触发器中包含了三种事件 insert update delete 语法格 ...
- zabbix web监控
深入浅出Zabbix 3.0 -- 第十章 Web 监控 http://www.mamicode.com/info-detail-1824545.html
- HDU多校Round 8
Solved:2 rank:141 D. Parentheses Matrix n,m有一个小于6的时候是一种构造方法 答案是n + (m - 2) / 2 (n > m) 都大于6的时候 可以 ...
- 【转载】linux下的zookeeper启动
zookeeper的安装目录:/usr/local/zookeeper-3.4.6/bin/zkServer.sh; 配置文件路径:../conf/zoo.cfg 端口 :2181: ZooKeepe ...
- Linux kernel 内存 - 页表映射(SHIFT,SIZE,MASK)和转换(32位,64位)
0. Intro 如下是在32位下的情况,32位下,只有三级页表:PGD,PMD,PTE 在64位情况下,会有四级页表:PGD,PUD,PMD,PTE 但是原理基本上是一样的,本文主要是想记录一下页表 ...
- Luogu P1297 [国家集训队]单选错位
P1297 [国家集训队]单选错位 题目背景 原 <网线切割>请前往P1577 题目描述 gx和lc去参加noip初赛,其中有一种题型叫单项选择题,顾名思义,只有一个选项是正确答案.试卷上 ...
- PAT 1146 Topological Order
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...