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的更多相关文章

  1. <LeetCode OJ> 268. Missing Number

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

  2. 【easy】268. Missing Number

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

  3. [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 ...

  4. 【LeetCode】268. Missing Number

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

  5. 268. Missing Number@python

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

  6. LeetCode Array Easy 268. Missing Number

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

  7. Java [Leetcode 268]Missing Number

    题目描述: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is ...

  8. LeetCode 268. Missing Number (缺失的数字)

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

  9. [LeetCode] 268. Missing Number ☆(丢失的数字)

    转载:http://www.cnblogs.com/grandyang/p/4756677.html Given an array containing n distinct numbers take ...

  10. [LeetCode] 268. Missing Number 缺失的数字

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

随机推荐

  1. MySQL--高性能MySQL笔记一

    链接管理与安全性: 每个客户端连接都在服务器进程中拥有一个线程. MySQL5.5以及更新的版本提供了一个API,支持线程池插件,可以使用池中少量的线程服务大量的链接. 认证基于用户名.密码和原始主机 ...

  2. optparse:让你轻松地与命令行打交道

    介绍 一个专门用于命令行参数解析的模块 使用 import optparse op = optparse.OptionParser() # 添加选项 op.add_option("--s&q ...

  3. table 边框问题

    对table设置css样式边框,分为几种情况:1.只对table设置边框2.对td设置边框3.对table和td技巧性设置表格边框4.对table和td设置背景,实现完美表格边框 以下DIVCSS5对 ...

  4. jmeter中的几种参数化场景

    1.request路径中引用参数 2.body中引用参数 3.parameter中引用参数 4.header中引用参数,如token这类跟用户相关参数 5.response assertion中引用参 ...

  5. Gym - 101987G Secret Code (概率+数学积分)

    题意:有A,B,C三个人要见面,每个人在[0,S]随机选择一个时间点作为见面时间,先到的那个人要等下一个人来了之后和他确认信息,然后马上就走. 例如,假如A先到,B其次,C最后到,那么A要等B到了之后 ...

  6. 【CF750E】New Year and Old Subsequence

    题目大意:给定一个长度为 N 的字符串,定义一个字串是"好的",当且仅当字串中含有一个 "2017" 的子序列,且不含有 "2016" 的子 ...

  7. 【51nod1672】区间交

    题目大意:给定一个长度为 N 的序列,以及 M 个区间,现从中选出 K 个区间,使得这些区间的交集区间的点权和最大,求最大值是多少. 题解: 发现直接选 K 个区间不可做,考虑从答案入手.设答案区间为 ...

  8. k8sDeployment控制器

    简写为deploy,是k8s控制器的另一种实现,它构建于ReplicaSet之上,可为pod和rs资源提供声明式更新. deploy控制器资源的大部分功能均可通过调用rs来实现,同时,还增添了部分特性 ...

  9. python时间 time模块和datetime模块

    一.time模块 time模块中时间表现的格式主要有三种: a.timestamp时间戳,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量 b.struct_time时间元组,共 ...

  10. 针对windows10 10.4号升级后VMware低版本不能使用的问题

    windows在10.4号下午发布的新版补丁升级,VMware老版本不能打开,之后发现好多小伙伴都在贴吧发帖子VMware不能用,提示升级,犯愁升还是不升,老版本的安装了好几个虚拟机,换成新版不知道能 ...