看到要求的空间、时间复杂度完全没有头绪。
只好看discussion
好巧妙。。完全想不到。。。还是没有经验啊。。。。
异或操作:相同为0,不同为1
stem:
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?
code:
public class Solution {
/*
2015-11-5
http://blog.csdn.net/is_zhoufeng/article/details/8112199
*/
public int singleNumber(int[] nums) {
int res=nums[0];
int len=nums.length;
for(int i=1;i