mycode   77.79%

class Solution(object):
def findDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
nums = sorted(nums)
for i in range(len(nums) - 1):
if nums[i+1] == nums[i]:
return nums[i]

参考

class Solution(object):
def findDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
count = [0] * len(nums)
for n in nums:
if count[n] == 1:
return n
count[n] += 1
return None

leetcode-hard-array-287. Find the Duplicate Number的更多相关文章

  1. leetcode 217. Contains Duplicate 287. Find the Duplicate Number 442. Find All Duplicates in an Array 448. Find All Numbers Disappeared in an Array

    后面3个题都是限制在1-n的,所有可以不先排序,可以利用巧方法做.最后两个题几乎一模一样. 217. Contains Duplicate class Solution { public: bool ...

  2. LeetCode 287. Find the Duplicate Number (python 判断环,时间复杂度O(n))

    LeetCode 287. Find the Duplicate Number 暴力解法 时间 O(nlog(n)),空间O(n),按题目中Note"只用O(1)的空间",照理是过 ...

  3. 287. Find the Duplicate Number hard

    287. Find the Duplicate Number   hard http://www.cnblogs.com/grandyang/p/4843654.html 51. N-Queens h ...

  4. [LeetCode] 287. Find the Duplicate Number 寻找重复数

    Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), pro ...

  5. LeetCode 287. Find the Duplicate Number (找到重复的数字)

    Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), pro ...

  6. 【LeetCode】287. Find the Duplicate Number

    Difficulty:medium  More:[目录]LeetCode Java实现 Description Given an array nums containing n + 1 integer ...

  7. 【LeetCode】287. Find the Duplicate Number 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 保存已经访问过的数字 链表成环 二分查找 日期 题目 ...

  8. [LeetCode] 287. Find the Duplicate Number 解题思路

    Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), pro ...

  9. [LeetCode] 287. Find the Duplicate Number(Floyd判圈算法)

    传送门 Description Given an array nums containing n + 1 integers where each integer is between 1 and n  ...

  10. 287. Find the Duplicate Number

    Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), pro ...

随机推荐

  1. windows2012获取明文密码

    windows 2012获取明文密码 导hash的话用常规的方法就可以. 修改注册表 reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contr ...

  2. MG301使用笔记

    [1]模块接收到的数据为16进制,显示乱码 配置命令:AT^IOMODE=1,1 设置对接收数据进行转换,当对端以 hex 格式发送数据,必须使用数据转换,否则数据无法完全上报.必须禁止使用缓存区.

  3. win10软件使用指南备忘录

    altrun:http://xbeta.info/altrun.htm timer:https://www.playpcesor.com/2009/04/timer.html (好像要上网打开) do ...

  4. 1. LVS概述

    1.LVS介绍 LVS是linux virtual server的简写linux虚拟服务器,是一个虚拟的服务器集群系统,可以再unix/linux平台下实现负载均衡集群功能 2.LVS组成 LVS由2 ...

  5. Android异常与性能优化相关面试问题-冷启动优化面试问题详解

    什么是冷启动: 冷启动的定义:冷启动就是在启动应用前,系统中没有该应用的任何进程信息.实际也就是要执行Application.onCreate()方法的那次启动. 冷启动 / 热启动的区别:热启动:用 ...

  6. C/C++小课之数组名是什么

    我们今天讨论数组名是什么东西,理解它有助于我们进一步理解和使用指针. 因为它涉及到了内存地址. 问题 数组名是什么?含义是什么? 思路 前提 一个值+1之后的变化可以反映出它的意义/含义. 前提的证明 ...

  7. web页面ios浏览器img图片的坑

    大家都知道ios浏览器有个默认的内置事件,就是长按屏幕,会放大预览你点击的内容. 不同浏览器效果各异,有的浏览器弹出提示框,预览图片或保存图片.主要呈下面2中形式.体验最差的就是后者,会直接将页面中的 ...

  8. Q&A(一)

    1.四种常见的无监督式任务? 聚类.可视化.降维.关联规则学习 2.什么是核外学习? 核外算法可以处理计算机主内存无法应对的大量数据.它将数据分割成小批量,然后使用在线学习技术从这些小批量中学习. 3 ...

  9. Oracle之:Function :func_float()

    create or replace function func_float(i_value float) return number is v_index number := 0; v_str var ...

  10. 2019CCPC秦皇岛赛区(重现赛)- J

    链接: http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1010&cid=872 题意: 鉴纯夏是一名成绩不太好的高中生. ...