Given an array of integers, every element appears twice except for one. Find that single one.

本题利用XOR的特性, X^0 = X, X^X = 0, 并且XOR满足交换律。

 class Solution(object):
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
s = 0
for x in nums:
s= s^x return s

single number II/III可以用位操作。用Hash table也可以通过OJ

class Solution(object):
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
dict = {}
for i in range(len(nums)):
if nums[i] not in dict:
dict[nums[i]] = 1
else:
dict[nums[i]] += 1 for word in dict:
if dict[word] == 1:
return word

最新文章

  1. 深入理解CSS定位中的偏移
  2. 基于HTML5 WebGL实现3D飞机叶轮旋转
  3. strlen() 函数
  4. Session的实现与存储
  5. Spring 定时任务 quartz的配置
  6. Constant is not finite! That's illegal. constant:inf'
  7. ExcelApplication 另存Excel的SaveAs函数
  8. Android L动画入门
  9. LeetCode OJ 85. Maximal Rectangle
  10. 巧妙利用ToArray()函数移除集合中的元素
  11. P2P应用中的NAT穿透问题
  12. spring框架应用系列二:component-scan自动扫描注册装配
  13. day319 1、正则表达式的定义及使用 2、Date类的用法 3、Calendar类的用法
  14. Contest2075 - 湖南多校对抗(csu1576)大数 Catalan Square
  15. Memento Mori (二维前缀和 + 枚举剪枝)
  16. POPUP_TO_CONFIRM的使用方法
  17. Mac 系统上安装Lua和SubmlimeText 编译器
  18. jsp jsp的基本语法
  19. 每天一个linux命令(1):find命令之exec
  20. PAT 1059 Prime Factors[难]

热门文章

  1. memcache 的内存管理介绍和 php实现memcache一致性哈希分布式算法
  2. vuejs全局api
  3. 匹配字符串的KMP算法
  4. PAT 1003. 我要通过!(20) JAVA
  5. 截取视图某一段另存为部分视图(Partial View)
  6. [转]一篇很全面的freemarker教程
  7. C#TCP通讯框架
  8. web—第四章css&第五章
  9. 深度学习(deep learning)
  10. C# FTP上传