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?
你的算法应该有线性时间复杂度,你可以不用额外的内存实现它吗?
思路:
相同的数异或结果为0.把所有数字异或一下即可。
//思路:按位异或^,相同的数经过偶数次异或结果为0,相当于没作用,所有数异或后仅剩那一个数