题目如下:

解题思路:题目很简单。先对数组排序,根据最大值和最小值即可求出公差,然后遍历数组,计算相邻元素的差,如果差不等于公差,即表示数字缺失。

代码如下:

class Solution(object):
def missingNumber(self, arr):
"""
:type arr: List[int]
:rtype: int
"""
arr.sort()
diff = (arr[-1] - arr[0])/(len(arr))
for i in range(len(arr)-1):
if arr[i] + diff != arr[i+1]:
return arr[i] + diff
return arr[0]

【leetcode】1228.Missing Number In Arithmetic Progression的更多相关文章

  1. 【LeetCode】268. Missing Number

    Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one ...

  2. 【LeetCode】268. Missing Number 解题报告(Java & Python)

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

  3. 【leetcode】 First Missing Positive

    [LeetCode]First Missing Positive Given an unsorted integer array, find the first missing positive in ...

  4. 【LeetCode】375. Guess Number Higher or Lower II 解题报告(Python)

    [LeetCode]375. Guess Number Higher or Lower II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...

  5. 【LeetCode】137. Single Number II 解题报告(Python)

    [LeetCode]137. Single Number II 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/single- ...

  6. 【LeetCode】306. Additive Number 解题报告(Python)

    [LeetCode]306. Additive Number 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http: ...

  7. 【LeetCode】452. Minimum Number of Arrows to Burst Balloons 解题报告(Python)

    [LeetCode]452. Minimum Number of Arrows to Burst Balloons 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https ...

  8. 【LeetCode】163. Missing Range

    Difficulty: Medium  More:[目录]LeetCode Java实现 Description Given a sorted integer array where the rang ...

  9. 【LeetCode】65. Valid Number

    Difficulty: Hard  More:[目录]LeetCode Java实现 Description Validate if a given string can be interpreted ...

随机推荐

  1. java:Oracle(聚合函数,多表查询,表之间的关系)

    1.聚合函数 --max,min,sum,avg,count,nvl(,) -- max:最大值 -- max既能取数字的最大值,也可以取字符串的最大值(英文字母排列顺序),根据场景实际意义来看,最好 ...

  2. 英特尔® Open Image Denoise 库有助于节省时间,提高质量

    在使用光线跟踪增强真实性与沉浸感时,游戏开发人员面临复杂的权衡.为了克服一系列挑战,英特尔创建了使用光线跟踪进行图像渲染的一整套解决方案,包含高性能开源滤波器.该解决方案已发布测试版,被集成至 Uni ...

  3. P4995 跳跳!

    喵喵喵好久没做过贪心的题目了,刷一下免得忘了嘤嘤嘤 题面 虽然是黄题,但是我承认并不是很难,so看代码吧还是.. #include<set> #include<map> #in ...

  4. EINT DINT ERTM DRTM EALLOW EDIS ESTOP0的理解

    本文参考以下资料整理 https://wenku.baidu.com/view/6b0d6906cf84b9d528ea7a66.html http://pangqicheng123.blog.163 ...

  5. Spring boot 整合 shiro 出现 org.apache.shiro.UnavailableSecurityManagerException: 错误

    最开始参考的是这个 文档 但是并没有解决我的问题,因为他的配置和我的是一样(差不多)的 https://www.cnblogs.com/ginponson/p/6217057.html 然后看到此篇博 ...

  6. 牛逼哄洪的 Java 8 Stream,性能也牛逼么?

    那么,Stream API的性能到底如何呢,代码整洁的背后是否意味着性能的损耗呢?本文对Stream API的性能一探究竟. 为保证测试结果真实可信,我们将JVM运行在 -server模式下,测试数据 ...

  7. 创建一个py文件并运行

    在 Linux 中,可以直接用vim 或者 vi 来编辑一个 python 文件 vim hello.py 进入编辑页面 #coding:utf-8 print("你好") (因为 ...

  8. 函数进阶装B操作

    三元表达式 条件成立时的返回值 if 条件 else 条件不成立时的返回值 x = 10 y = 20 print(f"x if x > y else y: {x if x > ...

  9. java集合之 ConcurrentHashMap的产生

    ConcurrentHashMap:  在java集合中 最常用的是ArrayList 效率最高的还是HashMap 但是线程不安全   HashTable是线程安全的(里面的方法是同步方法) 但相比 ...

  10. vue学习【四】vuex快速入门

    大家好,我是一叶,今天我们继续踩坑.今天的内容是vuex快速入门,页面传值不多的话,不建议vuex,直接props进行父子间传值就行,使用vuex就显得比较臃肿. 我们先预览一下效果,如图1所示. 图 ...