Skip to content

Instantly share code, notes, and snippets.

@cxtadment
Created September 11, 2015 00:09
Show Gist options
  • Select an option

  • Save cxtadment/67e230cf4be795b687bc to your computer and use it in GitHub Desktop.

Select an option

Save cxtadment/67e230cf4be795b687bc to your computer and use it in GitHub Desktop.
public class Solution {
/**
* @param A : An integer array
* @return : An integer
*/
public int singleNumberII(int[] A) {
// write your code here
if (A == null || A.length == 0) {
return -1;
}
int[] bit = new int[32];
int result = 0;
for (int i = 0; i < 32; i++) {
for (int j = 0; j < A.length; j++) {
bit[i] += A[j] >> i & 1;
bit[i] %= 3;
}
result |= (bit[i] << i);
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment