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 ...
随机推荐
- Altium Designer 只导出PCB元器件及标号的PDF文件的方法
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明. 作者:struct_mooc 博客地址:https://www.cnblogs.com/stru ...
- hiper、sitespeed性能工具
https://github.com/pod4g/hiper hiper: A statistical analysis tool for performance testing https: ...
- 第二篇 HTML 常用元素及属性值
常用元素及属性值 先和同学了解下,一部分常用的元素,区别以及属性,常用在哪里. 标签是由左右尖括号抱起来的,由开始标签开始,再由结束标签结束,里面内容则是元素,比如:<div>< ...
- C# 之 String.Empty
.NET Framework 类库,表示空字符串,此字段为只读,命名空间:System.程序集:mscorlib(在 mscorlib.dll 中). EG:protected string lo ...
- 深入理解python元类
类也是对象 在理解元类之前,你需要先掌握Python中的类.Python 中的类概念借鉴 Smalltalk,这显得有些奇特.在大多数编程语言中,类就是一组用来描述如何生成一个对象的代码段.当然在 P ...
- linux上如何安装mysql
下载rpm包: wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 安装rpm:rpm -ivh mysql-com ...
- 英国电信选择由 Canonical 开发的 Ubuntu OpenStack 作为云平台
英国电信(简称 BT,British Telecom)宣布,选择由 Canonical 开发的 Ubuntu OpenStack 作为云平台,该平台将有助于支持引入 5G 和光纤到户的连接. 作为 U ...
- Codeforces Round #581 (Div. 2) C. Anna, Svyatoslav and Maps (Floyd 算法,最短路)
C. Anna, Svyatoslav and Maps time limit per test2 seconds memory limit per test256 megabytes inputst ...
- h5转pb的两个坑
1.需要加上如下设置,否则转换前后输出可能不一致,这个主要针对dropout.BN层训练测试不一致 from keras import backend as K K.set_learning_phas ...
- 自定义前端框架(VUE+magicbox响应式风格)
1.用脚手架初始化一个vue项目swain $ vue create swain 2.安装几个常用插件