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 ...
随机推荐
- MySQL 帮助类 MySQLHelper
/// <summary> /// MySqlHelper操作类 /// </summary> public sealed partial class MySQLHelper ...
- python生成动态个性二维码
1 安装工具2 生成普通二维码3 带图片的二维码4 动态 GIF 二维码5 在Python程序中使用 一.安装 首先在python环境下运行, 打开cmd进入python27 进入scripts 然后 ...
- python学习小结-字典key,val互换
第一种,使用压缩器: >>> m = {'a': 1, 'b': 2, 'c': 3, 'd': 4} >>> zip(m.values(), m.keys()) ...
- 搭建jQuery开发环境
每个版本又分为一下两种:开发版和生产版: 版本 大小/KB 描述jquery-1.x.js 约288 开发版,完整无压缩,多用于学习,开发和测试jquery-2.x.js 约251 开发版,完整无压缩 ...
- eclipse配置Tomcat服务器server locations的方法
最近放弃了使用Myeclipse,转而使用eclipse作为开发工具,确实Myeclipse集成了太多东西,使得开发人员的配置越来越少,这不是个好事,使用eclipse后,有些地方就得自己去配置,比如 ...
- /etc/updatedb.conf配置文件
[root@localhost ~]# vi /etc/updatedb.conf PRUNE_BIND_MOUNTS = "yes" PRUNEFS = "9p afs ...
- 前k大金币(动态规划,递推)
/* ///题解写的很认真,如果您觉得还行的话可以顶一下或者评论一下吗? 思路: 这题复杂在要取前k大的结果,如果只是取最大情况下的金币和,直接 动态规划递归就可以,可是前k大并不能找出什么公式,所以 ...
- 59.关系型与document类型数据模型对比
现假设有如下两个类: class Department(object): def __init__(self, dept_id, name, desc, employees=[]): self.dep ...
- npm 使用教程
链接----------------------------------npm官网npm淘宝镜像 安装包----------------------------------npm install -g ...
- Jmeter使用笔记之断言
前言 Jmeter的断言方式有很多种,由于在工作中经常做的是API接口测试,所以这篇文章主要介绍如何对接口的字段进行解析,如何对解析出来的字段的值断言 了解API接口 Restful API 规范 协 ...