标签:log ber 三次 color bsp 提取 进制 time nbsp
public class Solution { /** * @param A : An integer array * @return : An integer */ public int singleNumberII(int[] A) { // write your code here int res = 0; for (int i = 0; i < 32; i++){ int rsBit = 0; for (int idx = 0; idx < A.length; idx++){ int bit = A[idx] >> i; bit &= 1; rsBit += bit; } rsBit %= 3; res += rsBit << i; } return res; } }
public class Solution { /** * @param A : An integer array * @return : An integer */ public int singleNumberII(int[] A) { // write your code here int ones = 0, twos = 0, threes = 0; for(int i = 0; i < A.length; i++){ //某数第一次进来,ones twos threes 1 0 0 //某数第二次进来,ones twos threes 0 1 0 //某数第三次进来,ones twos threes先1 1 1, 后 0 0 1 //某数第四次进来,ones twos threes 1 0 0 //循环 twos |= ones & A[i]; ones ^= A[i]; threes = ones & twos; //第三次来时抹去一二痕迹 twos &= ~three; ones &= ~three; } return ones; } }
lintcode83- Single Number II- midium
标签:log ber 三次 color bsp 提取 进制 time nbsp
原文地址:http://www.cnblogs.com/jasminemzy/p/7509782.html