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,5,3,2] 输出:2
示例 3:
输入:[5,1,5,2,5,3,5,4] 输出:5
提示:
- 4 <= A.length <= 10000
- 0 <= A[i] < 10000
- A.length 为偶数
class Solution {
public:
int repeatedNTimes(vector<int>& A)
{
int len = A.size();
map<int, int> save;
for(int i = 0; i < len; i++)
{
save[A[i]]++;
if(save[A[i]] >= 2)
return A[i];
}
return 0;
}
};
Leetcode961. N-Repeated Element in Size 2N Array重复N次的元素的更多相关文章
- LeetCode 961. N-Repeated Element in Size 2N Array (重复 N 次的元素)
题目标签:HashMap 题目给了我们一个size 为 2N 的int array,其中有 N + 1 个唯一的 数字,让我们找出那个重复的数字. 利用hashset,把每一个数字存入,一旦发现有重复 ...
- 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_easy】961. N-Repeated Element in Size 2N Array
problem 961. N-Repeated Element in Size 2N Array solution: class Solution { public: int repeatedNTim ...
- [Swift]LeetCode961. 重复 N 次的元素 | 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 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 ...
- 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 ...
- 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 ...
- 【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 ...
随机推荐
- P5390 [Cnoi2019]数学作业
P5390 [Cnoi2019]数学作业求子集异或和的和拆成2进制,假设有x个数这一位为1,剩下n-x个数对答案没有贡献,对于这一位而言,对答案的贡献就是,x个数选奇数个数的方案数*2^(n-x).由 ...
- LUOGU P3413 SAC#1 - 萌数(数位dp)
传送门 解题思路 首先这道题如果有两个以上长度的回文串,那么就一定有三个或两个的回文串,所以只需要记录一下上一位和上上位填的数字就行了.数位\(dp\),用记忆化搜索来实现.设\(f[i][j][k] ...
- from urllib import parse模块的使用
一.介绍 定义了url的标准接口,实现url的各种抽取 parse模块的作用:url的解析,合并,编码,解码 二.代码 方法一:urlparse 实现url的识别和分段 from urllib imp ...
- 记录一次hexo托管到coding失败,页面总是404,可是相同的代码托管到github是没问题的。
文章目录 问题描述: 问题原因: 问题解决 2019.1.23 问题,coding又挂了. 弃疗 个人博客:https://mmmmmm.me 源码:https://github.com/dataiy ...
- 20.multi_case02
# 多进程,使用Process对象 from multiprocessing import Process def f(name): print('hello', name) if __name__ ...
- Xcode9.4.1官方下载链接地址
More Downloads for Apple Developershttps://developer.apple.com/download/more/ Xcode 9.4.1https://dow ...
- sql 分组统计查询并横纵坐标转换
关于sql 分组统计查询,我们在做报表的时候经常需要用到;今天就在这里整理下; 先附上一段sql代码: if object_id(N'#mytb',N'U') is not null drop tab ...
- 使用 JDK11 遇到的问题
1.下载的 JDK 解压版中没有 jre 目录以及相应的包,需要通过命令自动生成 进入 JDK 的 bin 目录下,执行以下命令,然后会在 bin 目录下生成一个 jre 目录,需要将该 jre 目录 ...
- 【NOI2010】能量采集
题面 题目分析 对于第\((i,j)\)个位置,对答案的贡献为\(2*gcd(i,j)-1\). 所以有\(ans=2*\sum\limits_{i=1}^n\sum\limits_{j=1}^mgc ...
- img属性src的特点
img属性src的特点: src=“图片地址” 成功则加载图片,失败则显示alt文字和断裂的图片 src="" 则不加载,不显示alt文字和断裂的图片 因此当图片加载失败后,$(& ...