Single Number
2015-09-22 18:59
260 查看
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?
注意到A^A=0,所以A^B^A=B
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
public int singleNumber(int[] nums) { int result = 0; for (int i = 0; i < nums.length; i++) { result ^= nums[i]; } return result; }
注意到A^A=0,所以A^B^A=B
相关文章推荐
- python3 入门 (一) 基础语法
- ThinkPHP-给已上传图片生成缩略图并在列表显示
- HDU_3376_Matrix Again(最小费用流)
- Cookie
- android的消息处理机制(图文+源码分析)—Looper/Handler/Message[转]
- bounds的剖析
- Notification的使用(待完善)-〉添加点击取消,显示优化
- 0,22, 47, 120,(? ),290
- 火星信息安全研究院
- ./configure是干什么的?make install又是干什么的?
- hdu1166解题报告
- VirtualBox中开启Linux的SSH(CentOS)
- C++编写四则运算生成程序
- 堆栈
- $.ajax()方法详解
- 在JAVA中封装JSONUtils工具类及使用
- design pattern scard
- 不容忽视的网络安全
- Windows 64位下安装MySQL
- Android之地图