题目如下:

In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeated N times.

Return the element repeated N times.

Example 1:

Input: [1,2,3,3]
Output: 3

Example 2:

Input: [2,1,2,5,3,2]
Output: 2

Example 3:

Input: [5,1,5,2,5,3,5,4]
Output: 5

Note:

  1. 4 <= A.length <= 10000
  2. 0 <= A[i] < 10000
  3. A.length is even

解题思路:送分题。因为题目没有要求不能用额外的内存,所以我的方法是用字典保存每个数字出现的次数,从而找到出现N的数字。

代码如下:

class Solution(object):
def repeatedNTimes(self, A):
"""
:type A: List[int]
:rtype: int
"""
dic = {}
res = 0
for i in A:
dic[i] = dic.setdefault(i,0) + 1
if dic[i] == len(A)/2:
res = i
break
return res

【leetcode】961. N-Repeated Element in Size 2N Array的更多相关文章

  1. 【LeetCode】556. Next Greater Element III 解题报告(Python)

    [LeetCode]556. Next Greater Element III 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人 ...

  2. 【LeetCode】378. Kth Smallest Element in a Sorted Matrix 解题报告(Python)

    [LeetCode]378. Kth Smallest Element in a Sorted Matrix 解题报告(Python) 标签: LeetCode 题目地址:https://leetco ...

  3. 【LeetCode】162. Find Peak Element 解题报告(Python)

    [LeetCode]162. Find Peak Element 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/ ...

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

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

  6. 【LeetCode】961. N-Repeated Element in Size 2N Array 解题报告(Python & C+++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcod ...

  7. 【LeetCode】230. Kth Smallest Element in a BST

    Difficulty: Medium  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/kth-smallest- ...

  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】215. Kth Largest Element in an Array 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:移除最大值 方法二:排序 方法三:大顶堆 方 ...

随机推荐

  1. Qt 显示网页的控件

    Qt5.6以下的版本,基于QtWebkit控件Qt5.6以上的MSVC版本,基于 Chromium 的浏览器引擎 Qt WebEngineQt5.6以上的mingw 版本,只能采用QAxWidget ...

  2. tcpdump使用小记

    1, 类型的关键字主要包括:host, net, port: 2, 确定传输方向的关键字主要包括:src, dst, dst or src, dst and src: 3, 协议的关键字主要包括:fd ...

  3. shell 逐行比较两个文件的内容是否一样(行数相同)

    file1="1.txt" file2="2.txt" lines=`cat $file1 | wc -l` ;i<=$lines;i++)) do li ...

  4. kubernetes集群中移除Node

    例如要在集群中移出node2节点1)在master节点上执行: kubectl drain node2 --delete-local-data --force --ignore-daemonsets ...

  5. (转)Spring Boot干货系列:(三)启动原理解析

    转:http://tengj.top/2017/03/09/springboot3/ 前言 前面几章我们见识了SpringBoot为我们做的自动配置,确实方便快捷,但是对于新手来说,如果不大懂Spri ...

  6. CMDB 调研报告

    基础概念 1.什么是CMDB CMDB——配置管理数据库,通过识别.控制.维护,检查企业的IT资源,从而高效控制与管理不断变化的IT基础架构与IT服务,并为其它流程,例如事故管理.问题管理.变更管理. ...

  7. 在JMeter测试计划中如何控制业务比例

    作者:Selingchen 来源:CSDN 原文:https://blog.csdn.net/selingchen/article/details/47844375

  8. Http,Socket,TCP/IP 协议简述

    Http,Socket,TCP/IP 协议简述:https://blog.csdn.net/gordohu/article/details/54097841 TCP/IP协议,HTTP协议与webSo ...

  9. 数据持久化之轻量级Kv持久化(二)

    阿里P7Android高级架构进阶视频免费学习请点击:https://space.bilibili.com/474380680本篇文章将继续从以下两个内容来介绍轻量级Kv持久化: [SharedPre ...

  10. [已解决]报错: twisted 18.7.0 requires PyHamcrest>=1.9.0

    1.下载对应的Twisted,下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted 2.通过Anaconda3的Anaconda Promp ...