Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.

For example,
Given nums = [0, 1, 3] return 2.

class Solution(object):
def missingNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
n = len(nums)
return (1+n)*n/2-sum(nums)

Missing Number @leetcode的更多相关文章

  1. Missing Number ——LeetCode

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  2. 【LeetCode】268. Missing Number

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

  3. <LeetCode OJ> 268. Missing Number

    268. Missing Number Total Accepted: 31740 Total Submissions: 83547 Difficulty: Medium Given an array ...

  4. [LintCode] Find the Missing Number 寻找丢失的数字

    Given an array contains N numbers of 0 .. N, find which number doesn't exist in the array. Example G ...

  5. Leetcode-268 Missing Number

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

  6. Missing number

    Missing number 题目: Description There is a permutation without two numbers in it, and now you know wh ...

  7. hdu 5166 Missing number

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5166 Missing number Description There is a permutatio ...

  8. Missing Number, First Missing Positive

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

  9. HDU 5166 Missing number 简单数论

    Missing number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) [ ...

随机推荐

  1. 关于plantera

    在Plantera,您可以建立属于您自己的花园,并且看着新的植物,灌木,树木和动物一起生长. 当您进行游戏,扩张您的花园时,您会吸引圆滚滚的蓝色生物小助手们,它们将帮助您捡果子,收获您的植物 有时候会 ...

  2. kbmMW TkbmMWHashSHA256与Delphi 10.2 THashSHA2算出相同的结果

    procedure TForm2.Button3Click(Sender: TObject); var hashed:string; begin hashed:=TkbmMWHashSHA256.Ha ...

  3. ssh key建立后不能clone问题

    在建立了ssh密钥对之后,要将私钥添加,公钥key添加到gitlab的ssh keys里. 添加成功后,这个时候,你可以clone了! 总结:如果是遇到重复输入密码的情况,可能是ssh-key,的私钥 ...

  4. [LeetCode&Python] Problem 811. Subdomain Visit Count

    A website domain like "discuss.leetcode.com" consists of various subdomains. At the top le ...

  5. ajax提交post请求出现数组被截断情况的解决方法

    一.场景 php post 提交数据时传的数据时数组,没有多数据进行序列化处理.发现传到服务端时,部分数据丢失,查询了资料发现php对参数个数有限制,限制在php配置文件中(max_input_var ...

  6. CF1083(div1)

    A. The Fair Nut and the Best Path 题意:给定有点权,有边权的树,让你选择一条链(也可以是只有一个点),使得点权之和-边权最大. 思路:裸的树形DP,我们用dp[i]表 ...

  7. ubuntu mongodb backup/restore (备份和恢复)

    备份(导出) 1.导出单个collection-.json格式 mongoexport --host:127.0.0.1 --port:27017 --db test --collection tes ...

  8. dockerk个人学习(0)

    接下来几篇记录学习docker和ks的部署搭建环境和应用部署等

  9. stardog graphql 简单操作

    预备环境: 下载stardog 软件包 graphql 查询地址 创建一个简单数据库 ./stardog-admin db create -nstarwars graphql 查询方式 http 地址 ...

  10. php登陆绑定手机验证码使用阿里大于接口

    https://doc.alidayu.com/doc2/index.htm  一条0.045 元  新注册送10块