首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

[Leetcode] Single Number 一 & 2

2013-10-12 
[Leetcode] Single Number 1 & 2class Solution {public:int singleNumber(int A[], int n) {if (n 0)

[Leetcode] Single Number 1 & 2
class Solution {public: int singleNumber(int A[], int n) { if (n == 0) return 0; int x = A[0]; for (int i = 1; i < n; i++) x^=A[i]; return x; }};

?

?

class Solution {public: int singleNumber(int A[], int n) { int x[32]; memset(x, 0, sizeof(x)); for (int i = 0; i < n; i++) { for (int j = 0; j < 32; j++) { x[j] += (A[i] >> j) & (1); x[j] %= 3; } } int res = 0; for (int i = 0; i < 32; i++) { res += (x[i] << i); } return res; }};

?

?

热点排行