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
最新推荐文章于 2024-09-24 08:39:28 发布