Given an array of integers, every element appears three times except for one. Find that single one.
public class Solution {
public int singleNumber(int[] A) {
int ones=0,twos=0,threes=0;
for(int i=0;i<A.length;i++){
twos|=ones&A[i];
ones^=A[i];
threes=ones&twos;
ones&=~threes;
twos&=~threes;
}
return ones!=0?ones:twos;
}
}
Given an array of integers, every element appears twice except for one. Find that single one.
public class Solution {
public int singleNumber(int[] A) {
int ones=0;
for(int i=0;i<A.length;i++){
ones^=A[i];
}
return ones;
}
}