Missing Number @leetcode
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的更多相关文章
- Missing Number ——LeetCode
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- 【LeetCode】268. Missing Number
Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one ...
- <LeetCode OJ> 268. Missing Number
268. Missing Number Total Accepted: 31740 Total Submissions: 83547 Difficulty: Medium Given an array ...
- [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 ...
- Leetcode-268 Missing Number
#268. Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find ...
- Missing number
Missing number 题目: Description There is a permutation without two numbers in it, and now you know wh ...
- hdu 5166 Missing number
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5166 Missing number Description There is a permutatio ...
- Missing Number, First Missing Positive
268. Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find th ...
- HDU 5166 Missing number 简单数论
Missing number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) [ ...
随机推荐
- 官网下载的spring-framework的一些描述
刚下载下来是这个文件夹:
- mysql 函数 事务
mysql 中提供了许多内置函数 CHAR_LENGTH(str) 返回值为字符串str 的长度,长度的单位为字符.一个多字节字符算作一个单字符. 对于一个包含五个二字节字符集, LENGTH()返回 ...
- python Gevent – 高性能的Python并发框架
话说gevent也没个logo啥的,于是就摆了这张图= =|||,首先这是一种叫做greenlet的鸟,而在python里,按照官方解释greenlet是轻量级的并行编程,而gevent呢,就是利用g ...
- git stash,git cherry-pick
git stash: 备份当前的工作区的内容,从最近的一次提交中读取相关内容,让工作区保证和上次提交的内容一致.同时,将当前的工作区内容保存到Git栈中.git stash pop: 从Git栈中读取 ...
- 2018C语言助教总结
回顾 很荣幸得到各位老师的认可,担任计科3班和4班的C语言课程助教,很感谢车老师和牛老师一学期的帮助,使得我更好的担任助教一职.我班学生59名,很愉快的与同学们度过一个美好的学期,其实作为助教同样从学 ...
- xmodmap: unable to open display '' Error: Couldn't connect to XServer passing null display
/********************************************************************************* * xmodmap: unable ...
- 8个iPhone防盗秘籍 为手机和资料安全保驾护航
最近发现用x手机的朋友越来越多,今天一个朋友手机被偷,万分焦急,失财事小,电话里很多手机号码等重要信息都无法找回.为了让大家尽量安全使用自己的iPhone或苹果产品,哪怕丢失后也有最大的可能性找回,特 ...
- 本地和服务器(ubuntu)文件同步
秘钥登录远端服务器 rsync -avze 'ssh -i ./id_rsa' root@remoteIp:/xx/remotefile.txt ./localpath (./id_rsa为本地秘钥路 ...
- HDU 4666 最远曼哈顿距离
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4666 关于最远曼哈顿距离的介绍: http://blog.csdn.net/taozifish/ar ...
- 最短路--spfa+队列优化模板
spfa普通版就不写了,优化还是要的昂,spfa是可以判负环,接受负权边和重边的,判断负环只需要另开一个数组记录每个结点的入队次数,当有任意一个结点入队大于点数就表明有负环存在 #include< ...