leetcode Single Number python
#question : Given an array of integers, every element appears twice except for one. Find that single one.
#note : Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? class Solution(object):
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
intlen=len(nums)
if intlen == 0:
return -1
if intlen == 1:
return nums[0] ans=nums[0]
for i in range(1,intlen):
ans = ans ^ nums[i] return ans
leetcode Single Number python的更多相关文章
- [leetcode]Single Number II @ Python
原题地址:http://oj.leetcode.com/problems/single-number-ii/ 题意:Given an array of integers, every element ...
- LeetCode Single Number I II Python
Single Number Given an array of integers, every element appears twice except for one. Find that sing ...
- [LeetCode] Single Number III 单独的数字之三
Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...
- [LeetCode] Single Number II 单独的数字之二
Given an array of integers, every element appears three times except for one. Find that single one. ...
- [LeetCode] Single Number 单独的数字
Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...
- LeetCode Single Number I / II / III
[1]LeetCode 136 Single Number 题意:奇数个数,其中除了一个数只出现一次外,其他数都是成对出现,比如1,2,2,3,3...,求出该单个数. 解法:容易想到异或的性质,两个 ...
- LeetCode:Single Number II
题目地址:here 题目大意:一个整数数组中,只有一个数出现一次,其余数都出现3次,在O(n)时间,O(1)空间内找到这个出现一次的数 对于”只有一个数出现一次,其余数出现2次“的情况,很简单,只要把 ...
- LeetCode Single Number III
原题链接在这里:https://leetcode.com/problems/single-number-iii/ 题目: Given an array of numbers nums, in whic ...
- LeetCode——Single Number II(找出数组中只出现一次的数2)
问题: Given an array of integers, every element appears three times except for one. Find that single o ...
随机推荐
- css overflow
overflow-x,overflow-y的值相同等同于overflow overflow-x,overflow-y的值不同,其中一个被赋值visible,另一个被赋值为auto,scroll,hid ...
- 浏览器的重绘(repaints)与重排(reflows)
转:http://www.css88.com/archives/4991#more-4991 在项目的交互或视觉评审中,前端同学常常会对一些交互效果质疑,提出这样做不好那样做不好.主要原因是这些效果通 ...
- Silverlight学习(三)
最近对WCFRIA+MVVM+Prism有了初步的认识,能够简单的实现一些数据库的交互.这节主要讲的是Silverlight通过domainservice和ado.net实体数据模型与数据库的交互.本 ...
- js 完美兼容浏览器的复制功能
1,js结合swf的复制功能,完美兼容火狐,谷歌,360,ie8,使用示例:(ps:引入copy.swf比较重要,文件传送门 解压密码:http://www.bieanju.com/,为了防止360删 ...
- mysql和VS2010 C++链接过程中出现的问题
PS:二者连接的过程主要参考这篇博客园文章,http://www.cnblogs.com/justinzhang/archive/2011/09/23/2185963.html 这篇博客园的文章中的代 ...
- php变量的引用及函数的引用
Php变量的引用及函数的引用放回 变量的引用 $a="ABC"; $b =&$a; echo $a;//这里输出:ABC echo $b;//这里输 ...
- mysql 更新 语句中 的 safe_mode
在mysql5中,可以设置safe mode,比如在一个更新语句中UPDATE table_name SET bDeleted=0;执行时会错误,报:You are using safe update ...
- Less2css error 终极解决方案
使用sublime Text3 的时候,安装less2Css后,和很多人一样以为大功告成,开始要运行编译less文件,结果开始发现 于是乎开始搜索问题和解决方案,然后就有了下面的解决方案1 方案1:通 ...
- HTTP协议漫谈(转)
转自:http://www.cnblogs.com/CareySon/archive/2012/04/27/HTTP-Protocol.html HTTP的定义和历史 在一个网络中.传输数据需要面临三 ...
- Struts2技术详解(转)
1, 当Action设置了某个属性后,Struts将这些属性封装一个叫做Struts.valueStack的属性里.获取valueStack对象: ValueStack vs = (ValueStac ...