public class Solution {
public int singleNumber(int[] A) {
// O(1) Space
// Bit operation for ternery
int once = 0, twice = 0, thrice = 0; // Indicates how many times '1' appears
for(int i = 0; i < A.length; i++) {
twice |= (once & A[i]);
once ^= A[i];
thrice = ~(once & twice);
once &= thrice;
twice &= thrice;
}
return once;
}
}
Time: O(n);
Space: O(1);