leetcode-easy-others-268 Missing Number
mycode 80.25%
class Solution(object):
def missingNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
Max = len(nums)
t = {i for i in range(Max+1)}
f = set(nums)
return (t - f).pop()
参考
def missingNumber(nums):
"""
:type nums: List[int]
:rtype: int
"""
res = len(nums)
print(res)
for i in range(len(nums)):
res ^= (i ^ nums[i])
print(i,nums[i],i^nums[i],res)
return res
#最初设置返回值res是nums的长度,目标值i^现有值nums[i],那么如果i和nums[i]是相同的,异或的结果就是0,再让res^该结果,那么res仍等于res,这样说明i这个数是存在的,也就是说所有相同的数都被变成了0,剩下的就是缺失的数
leetcode-easy-others-268 Missing Number的更多相关文章
- <LeetCode OJ> 268. Missing Number
268. Missing Number Total Accepted: 31740 Total Submissions: 83547 Difficulty: Medium Given an array ...
- 【easy】268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- [LeetCode&Python] Problem 268. Missing Number
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 ...
- 268. Missing Number@python
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- LeetCode Array Easy 268. Missing Number
Description Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one th ...
- Java [Leetcode 268]Missing Number
题目描述: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is ...
- LeetCode 268. Missing Number (缺失的数字)
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- [LeetCode] 268. Missing Number ☆(丢失的数字)
转载:http://www.cnblogs.com/grandyang/p/4756677.html Given an array containing n distinct numbers take ...
- [LeetCode] 268. Missing Number 缺失的数字
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
随机推荐
- docker之常用命令
1) docker run -p : --name mysql -v d:/docker/mysql/conf:/etc/mysql/conf.d -v d:/docker/mysql/logs:/l ...
- 使用python的selenium库刷超星网课
网课很多看不完呀 所以动手做了一个基础的自动答题和下一节的程序 用到了python 3 selenium Chrome 如何自动化Chrome?https://www.cnblogs.com/eter ...
- js中new到底做了什么?如何重写new?
new 构造函数()执行顺序1.在堆中开辟对象内存空间, 记为obj2.在obj 中添加__proto__属性并指向 构造函数.prototype3.将构造函数中的this 指向obj4.执行构造函数 ...
- ab测试工具的使用
下载地址:http://httpd.apache.org/download.cgi#apache24 编译安装后在安装目录bin下可以找到ab执行程序 基本用法: ab -n 5000 -c 1000 ...
- Mybatis分页-利用Mybatis Generator插件生成基于数据库方言的分页语句,统计记录总数 (转)
众所周知,Mybatis本身没有提供基于数据库方言的分页功能,而是基于JDBC的游标分页,很容易出现性能问题.网上有很多分页的解决方案,不外乎是基于Mybatis本机的插件机制,通过拦截Sql做分页. ...
- MyBatis--把SQL带进Java
简单来看软件服务的工作流程:用户端界面操作请求<---->本地处理|远程服务程序拦截转发请求<---->服务端逻辑功能实现<--MyBatis用在这里-->数据库. ...
- pat(B)_1001
1001 害死人不偿命的(3n+1)猜想 (15 分) 卡拉兹(Callatz)猜想: 对任何一个正整数 n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把 (3n+1) 砍掉一半.这样一直反复 ...
- 第十篇.2、python并发编程之多进程
一 multiprocessing模块介绍 python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu_count()查看),在python中大部分情况需要使用多进程.P ...
- deepin下挂载的的Windows系统(NTFC)目录怎么是只读的???
关键命令: df-h sudo ntfsfix /dev/sda4 重启 参考博客:深度官网问题之大神回复
- php中限制ip段访问、禁止ip提交表单的代码
在需要禁止访问或提交表单的页面添加下面的代码进行判断就可以了. 注意:下边只是一个PHP限制IP的实例代码,如果您打算应用到CMS中,请自行修改. <?php /加IP访问限制 if(geten ...