【leetcode】Single Number II

   int singleNumber(int A[], int n) {
        int once = 0;
	int twice = 0;
	int three = 0;
	for (int i = 0; i < n; ++i)
	{
		//在计算新的once 前,计算twice
		twice |= once & A[i];
		//计算新的once
		once ^= A[i];
		three = ~(once & twice);
		//将3次的1都清理掉
		once &=  three;
        twice &= three;
	}
	return once;
    }

posted @ 2014-08-22 14:46  hrhguanli  阅读(133)  评论(0编辑  收藏  举报