Chinaunix首页 | 论坛 | 博客
  • 博客访问: 255932
  • 博文数量: 170
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1709
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-06 18:01
文章分类

全部博文(170)

文章存档

2016年(11)

2015年(130)

2014年(29)

分类: Java

2015-03-22 17:06:36

//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?
public class SingleNumber {
public int singleNumber(int[] A) {
       int a=A[0];
       for(int i=1;i          a=a^A[i];//异或
        return a;
   }
}

阅读(231) | 评论(0) | 转发(0) |
0

上一篇:SetMatrixZeroes

下一篇:threeSum

给主人留下些什么吧!~~