在大小为 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

提示:

  1. 4 <= A.length <= 10000
  2. 0 <= A[i] < 10000
  3. 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次的元素的更多相关文章

  1. LeetCode 961. N-Repeated Element in Size 2N Array (重复 N 次的元素)

    题目标签:HashMap 题目给了我们一个size 为 2N 的int array,其中有 N + 1 个唯一的 数字,让我们找出那个重复的数字. 利用hashset,把每一个数字存入,一旦发现有重复 ...

  2. 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 ...

  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. [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 ...

  5. 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 ...

  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 re ...

  7. 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 ...

  8. 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 ...

  9. 【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 ...

随机推荐

  1. 阿里云启动视频云V5计划,全面赋能生态合作伙伴

    9月25 - 27日,主题为数·智的2019云栖大会在杭州举行.在第三天的智能视频云专场中,阿里云研究员金戈首次对外发布视频云V5计划,释放视频IT基础设施红利,赋能生态合作伙伴,共促大视频产业发展. ...

  2. 云HBase备份恢复,为云HBase数据安全保驾护航

    摘要: 介绍了阿里云HBase自研备份恢复功能的基本背景以及基本原理架构和基本使用方法.   云HBase发布备份恢复功能,为用户数据保驾护航.对大多数公司来说数据的安全性以及可靠性是非常重要的,如何 ...

  3. thinkphp 模板渲染

    模板定义后就可以渲染模板输出,系统也支持直接渲染内容输出,模板赋值必须在模板渲染之前操作. 大理石平台价格表 渲染模板 渲染模板输出最常用的是使用display方法,调用格式: display('[模 ...

  4. 1002CSP-S模拟测试赛后总结

    晚上 我死了.T1全场AC只有我爆零了?? 还非常中二地写了个代码注释: 水题不假,但你不知道题水你更水么?? 碰到简单题就掉以轻心??还告诉自己不要掉以轻心…… 这下是真的滑天下之大稽了吧. 读题不 ...

  5. cf1147

    C——筛法 #include<bits/stdc++.h> using namespace std; ]; int main(){ cin>>n; ; ;i<=n;i++ ...

  6. python处理多线程之间事件通讯方法

    一.什么是事件 每执行一个事情,肯定有该事情的执行后状态,那事件就是该事情发生的信号 在程序中,多线程之间需要通讯,而事件就是方便线程之间的通讯 案例: 1.服务器启动需要5秒 2.客服端启动后去链接 ...

  7. [JZOJ 5782] 城市猎人

    思路: 并查集按秩合并维护出现时间. 最早连接时间就是树上连接最大值. \(qwq\)我居然把路径压缩和按秩合并打到一个程序里了...OvO #include <bits/stdc++.h> ...

  8. (37)C#Linq

    https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/let-clause 一.定义 Linq(Lang ...

  9. JavaScript开发人员必知的10个关键习惯

    还在一味没有目的的编写JavaScript代码吗?那么你就OUT了!让我们一起来看看小编为大家搜罗的JavaScript开发人员应该具备的十大关键习惯吧! 随着新技术的不断发展,JavaScript已 ...

  10. 初探JVM总结

    什么是JVM Java Virtual Machine(Java虚拟机)的缩写 .本质上是一个程序. java语言运行的平台,是ava跨平台的根本. java默认的三种类加载器 BootStrap C ...