在大小为 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. leetcode-157周赛-5214-最长定差子序列

    题目描述: class Solution: def longestSubsequence(self, arr: List[int], difference: int) -> int: dp = ...

  2. 关于Modelsim安装闪退

    在盗版Windows系统上,安装Modelsim时可能出现闪退. 现象表现为,在任务管理器中仍然有Modelsim的进程,但是看不到安装界面. 碰到这种情况可以尝试如下方法:退到安全模式下安装. 一般 ...

  3. Windows start

    启动一个单独的窗口以运行指定的程序或命令. START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]   ...

  4. 针对发送网络附件的java方法(使用Apache的jar包调用)

    1.先要在pom.xml文件中引入对应的jar包 <!--添加邮件的网络附件 start--> <dependency> <groupId>org.apache.c ...

  5. selenium python bindings 元素定位

    1. 辅助 Firepath Firefox是所有做前端的必不可少的浏览器因为firebug的页面元素显示很清晰.用selenium 去定位元素的时候Firefox还有一个非常友好的工具就是firep ...

  6. JS break语句和continue语句

    break语句 描述:break语句,用于无条件结束各种循环(退出循环)和switch. 说明:一般情况下,需要在break语句之前加一个条件判断.换句话说:就是条件成立了,就退出循环 continu ...

  7. POJ 3449 /// 判断线段相交

    题目大意: 给出多个多边形及其编号 按编号顺序输出每个多边形与其相交的其他多边形编号 注意一个两个多个的不同输出 将每个多边形处理成多条边 然后去判断与其他多边形的边是否相交 计算正方形另外两点的方法 ...

  8. Mapped Statements collection does not contain value for xxx.xxx 错误原因&解决方案

    先贴出详细的报错信息 2019-11-05 10:10:00 [executor-1] ERROR [org.quartz.core.JobRunShell:225] - Job DEFAULT.ef ...

  9. Linux 下 cs8900a 的移植说明

    为 cs8900a 建立编译菜单 1. 拷贝到文件 把 cs8900a 的压缩包拷贝到 arm 用户下的 dev_home/localapps/ [arm@localhost localapps]$ ...

  10. python Selenium chromedriver 自动化超时报错:你需要使用多标签保护罩护体

    在使用selenium + chrome 作自动化测试的时候,有可能会出现网页连接超时的情况 如果出现网页连接超时,将会导致 webdriver 也跟着无法响应,不能继续进行任何操作 即时是去打开新的 ...