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;
}
相关文章
- 02-16[LeetCode]374. Guess Number Higher or Lower ★
- 02-16【LeetCode每天一题】Fibonacci Number(斐波那契数列)
- 02-16【leetcode】509. Fibonacci Number
- 02-16【LEETCODE】44、509. Fibonacci Number
- 02-16(Easy) Fibonacci Number LeetCode
- 02-16[leetcode]Remove Duplicates from Sorted Array II @ Python
- 02-16LeetCode::Remove Duplicates from Sorted List II [具体分析]
- 02-16[LeetCode] Remove Duplicates from Sorted List II
- 02-16【leetcode】507. Perfect Number
- 02-16[LeetCode] 65. Valid Number