[leetcode] 【数组】 137. Single Number II

Given an array of integers, every element appears three times except for one. Find that single one.

Note:

Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

题解

class Solution {
public:
int singleNumber(vector<int>& nums) {
const int sizeint=sizeof(int)*8;
vector<int> count(sizeint);
for(auto i: nums)
{
for(int j=0;j<sizeint;j++)
{
count[j]+=(i>>j) &1;
count[j]%=3;
}
}
int res=0;
for(int i=0;i<sizeint;i++)
res+=(count[i]<<i);
return res;
}
};

LeetCode 137：Single Number II

2015-06-01 22:36:27

【LeetCode-面试算法经典-Java实现】【137-Single Number II（只字出一次的数字II）】

2015-08-18 06:24:21

LeetCode(137)Single NumberII

2014-02-09 10:15:27

leetcode-java-137. Single Number II

2016-06-28 11:35:02

Leetcode 137 Single Number II 仅出现一次的数字

2015-08-18 10:34:47

【LeetCode】【Python题解】Single NumberII

2014-09-15 23:08:07

LeetCode 137. Single Number II 解题报告

2016-10-26 20:39:27

LeetCode || Single Number II

2014-04-09 23:35:07

Leetcode_137_Single Number II

2015-01-19 19:00:30

single-number、single-number2，数组中只出现一次的数字

2016-05-27 20:17:00