leetcode-easy-array-136. Single Number
mycode 75.80%
class Solution(object):
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
res = nums[0]
for i in nums[1:]:
res = res ^ i
return res
参考:
class Solution:
def singleNumber(self, nums):
store = set()
for num in nums:
if num in store:
store.remove(num)
else:
store.add(num)
return list(store)[0]
leetcode-easy-array-136. Single Number的更多相关文章
- [LeetCode&Python] Problem 136. Single Number
Given a non-empty array of integers, every element appears twice except for one. Find that single on ...
- LeetCode 136. Single Number C++ 结题报告
136. Single Number -- Easy 解答 相同的数,XOR 等于 0,所以,将所有的数字 XOR 就可以得到只出现一次的数 class Solution { public: int ...
- leetcode 136 Single Number, 260 Single Number III
leetcode 136. Single Number Given an array of integers, every element appears twice except for one. ...
- LeetCode 136. Single Number(只出现一次的数字)
LeetCode 136. Single Number(只出现一次的数字)
- leetcode 136. Single Number 、 137. Single Number II 、 260. Single Number III(剑指offer40 数组中只出现一次的数字)
136. Single Number 除了一个数字,其他数字都出现了两遍. 用亦或解决,亦或的特点:1.相同的数结果为0,不同的数结果为1 2.与自己亦或为0,与0亦或为原来的数 class Solu ...
- 136. Single Number - LeetCode
Question 136. Single Number Solution 思路:构造一个map,遍历数组记录每个数出现的次数,再遍历map,取出出现次数为1的num public int single ...
- LeetCode(137) Single Number II
题目 Given an array of integers, every element appears three times except for one. Find that single on ...
- 【LeetCode】136. Single Number 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 异或 字典 日期 [LeetCode] 题目地址:h ...
- LeetCode 136 Single Number(仅仅出现一次的数字)
翻译 给定一个整型数组,除了某个元素外其余元素均出现两次. 找出这个仅仅出现一次的元素. 备注: 你的算法应该是一个线性时间复杂度. 你能够不用额外空间来实现它吗? 原文 Given an array ...
- [LeetCode] 136. Single Number 单独数
Given a non-empty array of integers, every element appears twice except for one. Find that single on ...
随机推荐
- bilibili小程序项目总结
1.关于mock的使用 第一步:先到Mock官网(http://mockjs.com/)上面熟悉一下基本用法 第一步:具体使用实例: 下载wxMock.js和mock.js文件 下载地址:https: ...
- DedeAMPZ 网吧能安装却不能打开网站
只需把 监听IP的连接里的 LMHOSTS查询 禁用就行了. 方法: 连接属性-->TCP/IP 协议属性-->WINS 选项卡-->去掉 启用 LMHOSTS查询 前面的勾. by ...
- Delphi 触发异常的方法
- CPP标准模板库 随笔
对于无序容器而言,其次序是不固定的,就算添加一个元素,也可能全盘改变次序.唯一可以保证的是,内容相同的元素会相邻.(eg: 23,1,1,25,3,27,5,7,11,11) 迭代器的种类: 1,前向 ...
- Linux运维课程体系大纲
Linux入门: Linux系统管理: Linux服务及安全管理: httpd,lamp,lnmp Cache:memcached,varnish(缓存系统) ...
- double to long
obj to double obj to long instance of Bigdecimal public static void main(String[] args) throws Parse ...
- (转) Linux安装启动FTP服务
Linux安装启动FTP服务 Linux服务器默认是没有开启FTP服务的.也没有FTP服务器,为了文件的传输需要用到FTP服务器,以典型的vsftpd为例.vsftpd作为FTP服务器,在Linux系 ...
- tomcat访问日志
* %a - Remote IP address # 远程ip地址 * %A - Local IP address # 本地ip地址 * %b - Bytes sent, excluding HTTP ...
- C++最快获取像素值
HDC hdc, hdcTemp; RECT rect; BYTE* bitPointer; int x, y; int red, green, blue, alpha; while(true) { ...
- puppet使用rsync模块同步目录和文件
puppet使用rsync模块同步目录和文件 2013-09-23 14:28:57 分类: LINUX 环境说明: OS : CentOS5.4 ...