神一样的代码:

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;
}
posted on 2015-11-19 12:42  peterTong  阅读(220)  评论(0)    收藏  举报