您的位置:首页 > 其它

【leetcode】Single Number II

2014-08-22 14:46 295 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: