public class Solution {public int singleNumber(int[] A) {for(int i=1; i<A.length; i++){A[i]^=A[i-1];}return A[A.length-1];}
}
分析:这个题目限制了空间复杂度和时间复杂度, 考点是位操作里面的异或消除偶数对的特征。(^ 按位异或运算符:如果一个位是1,另一个位是0,结果位就是1。如果相应的位相同,结果位就是0;)
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?