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 ...
随机推荐
- web api (.NET 4.5)
摘自http://blog.csdn.net/fangxing80/article/details/7318289 在刚刚发布的 ASP.NET MVC 4 中,有一个值得注意的新特性——Web Ap ...
- 点击TextView浏览器打开指定网页
直接上代码: /** * 点击跳转到版权页面 */ private void getCopyRight() { // TODO Auto-generated method stub TextView ...
- Oracle入门学习笔记
参考文献 中文教程 http://wenku.baidu.com/view/b425f404e87101f69e319566.html 经典教程 http://wenku.baidu. ...
- Debug编辑通过转Release找不到命名空间
首先查看缺少命名空间在哪个项目中 然后看缺少命名空间项目中bin/Release有没有相关文件 如果没有对该项目进行Release编译然后在编译所有项目
- iOS设计模式解析(五)责任链模式
责任链模式:使多个对象都有机会处理请求,从而避免发送者和接受者之间发生耦合. 应用场景: 有多个对象可以处理请求,而处理程序只有在运行时才能确定 例如: 英雄联盟中伤害计算,伤害类型分为AP.AD.真 ...
- 如何让tableView展示数据
设置数据源对象 self.tableView.dataSource = self; 数据源对象要遵守协议 @interface ViewController () <UITableViewDat ...
- C# for循环①护栏长度 ②广场砖面积 ③判断闰年平年
// static void Main(string[] args) { const double PI = 3.14; const int BAR_U ...
- zoj1027 Human Gene Functions
一道动态规划,两个串进行匹配,不同字母匹配的值不一样,也可以和空格匹配(空格不能与空格匹配),求最大的匹配值. 数据很弱,每个串都在100以内. 定义dp[i][j]为第一个串前i个数和第二个串前j个 ...
- 关闭编译器FPO优化
// The release libs don't include FPO debug information, so FPO// optimization will interfere with s ...
- Less2css error 终极解决方案
使用sublime Text3 的时候,安装less2Css后,和很多人一样以为大功告成,开始要运行编译less文件,结果开始发现 于是乎开始搜索问题和解决方案,然后就有了下面的解决方案1 方案1:通 ...