您的位置:首页 > 其它

leetcode - Single Number II

2013-10-14 10:34 330 查看
class Solution {
public:
int singleNumber(int A[], int n) {
// Note: The Solution object is instantiated only once and is reused by each test case.
if (n<=0)
return 0;
int bits[32];
int i, j;
for (i=0; i<32; i++)
bits[i]=0;
for (i=0; i<n; i++)
for (j=0; j<32; j++)
bits[j] = ( bits[j] + ((A[i]>>j)&1) ) % 3;
int ans=0;
for (i=0; i<32; i++)
ans = ans+(bits[i]<<i);
return ans;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: