1
class Solution {
2
public int singleNumber(int[] nums) {
3

4
int[] bitCount = new int[32]; // 32 bit number
5

6
// Count occurrence of each bits in each num
7
for (int i = 0; i < bitCount.length; i++) {
8
for (int num : nums) {
9
if ((num & 1 << i) != 0) // If ith bit in "num" is 1
10
bitCount[i]++;
11
}
12
}
13

14
// Check the bit which doesn't have count multiple of 3 (i.e. no of repeating digits in input
15
// nums arr)
16
// and add it to the result.
17
int result = 0;
18
for (int i = 0; i < bitCount.length; i++) result += (bitCount[i] % 3) * (1 << i);
19

20
return result;
21
}
22
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0