leetcode Single Number python
2015-12-19 12:09
573 查看
#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
相关文章推荐
- python yield 学习笔记
- Python 基础【第八篇】变量
- 如何使用pdb调试python程序
- Python Tornado 使用经验
- mac下已有pyhon2.7,装了python3 之后,怎么调用python3啊
- 业务系统JSON日志通过python处理并导入Mysql方案
- Python Network Programming(2)---地址转换函数
- Python: easy_install & pip 下载PyPi 公共资源库的工具
- [python]Numpy快速入门
- 安装python的图形处理库: pillow
- Python 基础【第七篇】集合
- 用conda管理Python包
- python数据类型详解
- 最大似然估计(MLE)的一些公式与定理(python实践)
- 再看Python.第2天
- 再看Python.第1天
- My way to Python - Day06 socket基础
- Python 面向对象 三
- Python 面向对象 四
- 一入Python深似海--print