首页 > 代码库 > 【leetcode】Single Number II

【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;
    }

【leetcode】Single Number II