public static int singleNumber(int[] nums) { int once = 0; int twice = 0; for (int i = 0; i < nums.length; i++) { twice |= once & nums[i]; once ^= nums[i]; int not_three = ~(once & twice); once = not_three & once; twice = not_three & twice; } return once; }