https://oj.leetcode.com/problems/single-number-ii/
http://blog.csdn.net/linhuanmars/article/details/22645599
public class Solution { public int singleNumber(int[] A) { return singleNumber_BitCompare(A, 3); } private int singleNumber_BitCompare(int[] A, int k) { int toReturn = 0; for (int i = 0 ; i < 32 ; i ++) { int tocompare = 1 << i; int occur = 0; for (int num : A) { if ((num & tocompare) != 0) // use != 0 rather than ==1 occur ++; } if (occur % k == 1) // normally it would be 0 toReturn |= tocompare; } return toReturn; } }