137. Single Number II

T: O(n)

S: O(1)

```java
class Solution {
    public int singleNumber(int[] nums) {
        int[] bits = new int[32];
        for (int x : nums) {
            for (int i = 0; i < 32;i++) {
                bits[i] += (x >> i)&1; // convert to binary
            }
        }
        int result = 0;
        for (int i = 0; i < 32;i++) {
            result += (bits[i]%3)<<i; // convert back to decimal 
        }
        return result;
    }
}
```

Last updated