在大小为 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. CF886F Symmetric Projections

    题意:给你平面上n个点,问有多少条过原点的直线,使得这些点在该直线上的投影(做垂直,对应点)形成对称图形?n<=2000. 标程: #include<bits/stdc++.h> # ...

  2. ctrl+shift+k取消

    因为typora软件和搜狗输入法软件的快捷键重合了,ctrl+shift+k在typora中是代码块的快捷键,而在搜狗输入法中是软键盘快捷键,显然软键盘不重要. 搜狗输入法的ctrl+shift+k取 ...

  3. MySQL Download

    { http://www.wampserver.com/#wampserver-64-bits-php-5-6-25-php-7 }

  4. R语言 包

    R语言包 R语言的包是R函数,编译代码和样本数据的集合. 它们存储在R语言环境中名为"library"的目录下. 默认情况下,R语言在安装期间安装一组软件包. 随后添加更多包,当它 ...

  5. 剑指Offer-16:合并两个有序链表

    题目描述: 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则. 例如A链表为1-3-5-7,B链表为2-4-6-8.所以合并后的新链表C为1-2-3-4-5- ...

  6. HDU5377

    题意:给sum,m组询问,每组x,y求\(x^t=y\mod p,p|sum\),p是素数,求最小的t 题解:先处理sum的所有质因子p,求出p的原根rt,\(rt^a=x\mod p,rt^b=y\ ...

  7. iOS开发之SceneKit框架--SCNView.h

    1.SCNView 在macOS中,SCNView是NSView的子类,在iOS和tvOS中,SCNView是UIView的子类.SCNView用于显示SceneKit的3D场景,而需要设置场景的相关 ...

  8. 17.splash_case03

    # python执行lua脚本 import requests from urllib.parse import quote lua = ''' function main(splash) retur ...

  9. unittest零碎知识

    给unittest传值: class TesCase(unittest.TestCase): # k1 = expect = msg = None # requests的返回结果和用例的预期值 def ...

  10. cmd以管理员打开